Xamarin.InAppPurchase: ReceivedResponse not invoked (StoreKit bindings problem?)

KatalysticalKatalystical USMember

Hello everybody,

after months of hard work creating a new app for our social app, I'm stuck with IAPs in iOS.
Long story short:

After the migration to the Unified API and an updated Xam.IAP component, my Products were not being displayed correctly in my "buy-menu" anymore. (Especially the price information, when trying to retrieve through FindProduct(...).
Just a few days earlier, everything still worked.
IAPs are not live at the moment, but ready for use in conjunction with iTunes sandbox servers/Env.

A short examination:
FindProduct just returned a placeholder product with the float Price being 0 and FormattedPrice being an empty string.

Reason:
Obviously, the requested products haven't been received from the iTunes Servers, neither as valid, nor as invalid products.

Okay, as I evaluated this problem for a long time now and checked every point on the "IAPs checklist" (every potential reason it could not work, like missing Banking&Tax/iOS Paid Application contracts in iTunes Connect) I started disassembling the component (sorry @KMullins) and manually bring it to life in a new project.

I came to the conclusion (and proof) that neither ReceivedResponse, nor RequestFailed of the corresponding SKProductsRequest get invoked - there's just the RequestFinished event occuring shortly after starting the request.
A deeper analysis showed there're some WeakDelegates underneath (in the binding lib of StoreKit).

As I experienced some strange behaviour regarding WeakDelegates and WeakRefs in other classes before (since the upgrade to Unified API), I suppose it's a similar issue. It seems in some situations, WeakRefs/WeakDelegates targets get crunched by the GC some time before they are invoked/used. In another class, I just fixed this by not using Weaks in these places. Did SGen become this aggressive?

However, I'm just assuming, as I'm baffled with this issue.
The main problem is, a pure StoreKit implementation would take a longer time to be created in a similar manner - and if it's a SK bug, this wouldn't fix it at all.
Is anybody experiencing similar problems?

Greetings from Germany,
Kevin

P.S. if anybody needs more information or context on this issue, just tell me. As this issue targets an app with more-or-less live IAPs, a sample app with Xam.IAP set to testing mode would make no sense.

Posts

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Hi @Katalystical,

    I'll take another look at it and see what's happening. I do know that the linker can become over aggressive in Unified API applications right now and strip out parts of referenced libraries so you might want to take a look at your Linker Settings and see if that makes a difference.

    And you are right, it could be an issue with the StoreKit bindings in the Unified API. Again, I'll take a look at thing on this end as this component was updated with an older build of the Unified APIs so something could be amiss there.

    Please let me know if you find anything else out or have an other questions.

    Thanks,

    Kevin

  • KatalysticalKatalystical USMember
    edited January 2015

    Hi @KMullins,

    Deriving from the SKProductsRequest from StoreKit and overriding the WeakDelegate Property fixed it:
    (just a 30sec experiment)

    using System;
    using Foundation;
    
    namespace StoreKit
    {
        public class IaProductsRequest : SKProductsRequest
        {
            public IaProductsRequest (NSSet pis) : base(pis)
            {
            }
    
            private NSObject _weakDelegate;
    
            public override NSObject WeakDelegate {
                get {
                    return _weakDelegate;
                }
                set {
                    _weakDelegate = value;
                }
            }
        }
    }
    

    Of course, this needs a disassembled Xamarin.InAppPurchase component/lib, this derived class and a modified InAppPurchaseManager, which uses this class when doing the request. (this._productsRequest in InAppPurchaseManager becomes a IaProductsRequest) - so, this is no long-term solution.

    This example shows there's some problem regarding the GC or the way the StoreKit bindings are written.

    Thanks,
    Kevin

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Hi @Katalystical,

    Great work figuring out what went wrong here... I'm looking into it right now and hope to have a permanent solution in place very soon. Looks like it could possibly be an issue with the binding or something weird going on with the garbage collector.

    Thanks,

    Kevin

  • ChristianLammelChristianLammel DEMember
    edited March 2015

    I had a similar problem after Updating to Unified API. What my problem was: I used the events SKProductRequest.ReceivedResponse and RequestFailed with anonymous functions instead of a full featured SKProductsRequestDelegate derived class, and that worked before.

    Now i am using a full delegate implementation and all is back to normal.

    Xamarin.iOS
    Version: 8.8.1.9 (Indie Edition)
    Hash: 7e1f69e
    Branch:
    Build date: 2015-03-12 15:35:49-0400

Sign In or Register to comment.