Question

I'm using the latest MKStoreKit to make an in-app purchase. The problem I've ran into is that when the app doesn't have internet when it starts, the products aren't loaded from the app store. If I then run

- (void) buyFeature:(NSString*) featureId
         onComplete:(void (^)(NSString* purchasedFeature, NSData*purchasedReceipt)) completionBlock         
        onCancelled:(void (^)(void)) cancelBlock;

Then it never runs either of onComplete or onCancelled because it returns here when it doesn't find the purchasable object.

NSArray *allIds = [self.purchasableObjects valueForKey:@"productIdentifier"];
int index = [allIds indexOfObject:productId];

if(index == NSNotFound) return; <-- IT RETURNS HERE

SKProduct *thisProduct = [self.purchasableObjects objectAtIndex:index];
    SKPayment *payment = [SKPayment paymentWithProduct:thisProduct];
    [[SKPaymentQueue defaultQueue] addPayment:payment];

It doesn't even send back an error so the user doesn't get any message.

I guess this should be a common problem? How do I handle it in the best way?

Was it helpful?

Solution

I solved it by evaluating...

MKStoreKit.sharedManager.pricesDictionary.count == 0

...to know if I should tell the user that the App Store is unavailable for purchases. And then I tried to reload the product data by using this approach...

https://github.com/MugunthKumar/MKStoreKit/issues/75

...everytime the user was interested in buying and the App Store was unavailable according to above.

To update the UI when the products was downloaded and ready for purchase, I listened to this Notification...

[NotificationCenter addObserver:self
                       selector:@selector(productsFetched:)
                           name:kProductFetchedNotification
                         object:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top