Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NotImplementedException in Plugin.InAppBilling on iOS with .NET MAUI #644

Open
tecomunico opened this issue Nov 11, 2024 · 0 comments

Comments

@tecomunico
Copy link

Bug Information

  • Version Number of Plugin: 8.0.5
    
  • Device Tested On: iPhone 14 Pro Max (physical device)
    
  • Simulator Tested On: iPhone 14 Pro (iOS 18.1)
    
  • Version of VS: Visual Studio for Mac 17.6
    
  • Version of .NET MAUI: 8.0.0
    
  • Other Relevant Versions:
    
  • .NET MAUI controls: 8.0.0.3
    
  • Microsoft.Maui.Essentials: 8.0.0.3
    

Steps to reproduce the Behavior

  1. Installed Plugin.InAppBilling version 8.0.5 in a .NET MAUI project.
    
  2. Set up in-app purchase functionality according to the documentation, including initializing CrossInAppBilling.Current and calling PurchaseAsync.
    
  3. Ran the app on a physical iOS device (iPhone 14 Pro Max) using Debug mode.
    
  4. Triggered the purchase process by clicking the subscription button.
    

Expected Behavior

The app should connect to the App Store, initiate the purchase, and handle any errors or completion events as expected.

Actual Behavior

The app throws a System.NotImplementedException with the message: "This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation."

Code snippet

private async void OnSubscribeClicked(object sender, EventArgs e)
{
LogToFile("OnSubscribeClicked - User initiated subscription process.");

var billing = CrossInAppBilling.Current;
if (billing == null)
{
    LogToFile("InAppBilling service not initialized.");
    return;
}

try
{
    LogToFile("Attempting to connect to billing service...");
    bool connected = await billing.ConnectAsync();

    LogToFile($"Billing service connected: {connected}");
    if (!connected)
    {
        LogToFile("Connection to billing service failed.");
        return;
    }

    LogToFile("Attempting purchase...");
    var purchase = await billing.PurchaseAsync("com.jabezsoftware.jabeztime.annual", ItemType.Subscription, "payload");

    LogToFile($"Purchase state: {(purchase != null ? purchase.State.ToString() : "null")}");
    if (purchase != null && purchase.State == PurchaseState.Purchased)
    {
        LogToFile("Purchase successful. Activating subscription...");
        await Services.TrialManager.ActivateSubscription();

        SubscriptionMessage.IsVisible = true;
        SubscribeButton.IsVisible = false;
        LogToFile("Subscription successfully activated.");
    }
    else
    {
        LogToFile("Purchase was not completed or canceled.");
    }
}
catch (InAppBillingPurchaseException purchaseEx)
{
    LogToFile($"InAppBillingPurchaseException: {purchaseEx.Message}");
}
catch (Exception ex)
{
    LogToFile($"General Exception in OnSubscribeClicked: {ex.Message}");
}
finally
{
    LogToFile("Disconnecting from billing service...");
    await billing.DisconnectAsync();
    LogToFile("Disconnected from billing service.");
}

}

    public static void LogToFile(string message)
    {
        try
        {
            var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", "Caches", "log.txt");
            File.AppendAllText(path, $"{DateTime.Now}: {message}\n");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Failed to write log: {ex.Message}");
        }
    }

Error Message

Here is the error message displayed in the output:

System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
at Plugin.InAppBilling.CrossInAppBilling.get_Current()
at JabezTime.Views.SubscriptionPage.OnSubscribeClicked(Object sender, EventArgs e) in /Users/edgargarcia/Projects/Jabez Time/Jabez Time/Views/SubscriptionPage.xaml.cs:21
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:176
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:58
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:94
at JabezTime.Program.Main(String[] args) in /Users/edgargarcia/Projects/Jabez Time/Jabez Time/Platforms/iOS/Program.cs:13

Screenshots

Screenshot 2024-11-11 at 2 13 17 PM

Additional Notes

To help trace the issue, I implemented a logging mechanism that writes to a log.txt file to track the execution flow within the app. Despite this, I have been unable to pinpoint the exact source of the error. I’ve tested the app on physical devices in both Debug and Release modes, utilizing all available debugging tools in Visual Studio for Mac and Xcode. However, the error persists without providing a clear trace to diagnose the cause.

I would appreciate any further guidance on resolving this issue, as I’ve followed the configuration steps outlined in the documentation and have double-checked that the plugin is correctly installed and referenced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant