Store Observer not being called always

Posted by Nixarn on Stack Overflow See other posts from Stack Overflow or by Nixarn
Published on 2010-06-18T09:18:49Z Indexed on 2010/06/18 9:23 UTC
Read the original article Hit count: 188

Has anyone else here experienced problems with their Store Observer class not being called always when the user for instance cancels a request (or purchases something)

We just had our update that brought in app purchases go live last night, and before that we had obviously tested everything tons of times against the Sandbox and everything was working fine.

Now however, when the update went live in a real environment we keep getting issues with the store.

For instance, in a freshly booted iPhone / iPod, the first time you run the app, if you then try to make a purchase and then immediately cancel it from the first dialog, it seems as if the callback for the cancel is not getting called. If you then restart the app it seems as if it always works after that, or at least. Same thing with other callbacks, seems as if our store observer isn't listening as the callbacks aren't being registered on the phone. One example of this is if you purchase something, then nothing will happen (if this is the first time the app is launched at least). You get the purchase successful dialog from the app store but it seems as if our own code isn't called. If you then quit the app and restart it the callback gets called.

Same problem happens if you for instance try to start a request to download all previous purchases and then immediately cancel it as the first dialog pops up, if you do that then the callback for a failed restore is not called, until you then restart the app and try it again, then it always seems to work.

The way we have implemented our store observer is by creating a custom class that's implements the SKPaymentTransactionObserver interface.

@interface StoreObserver : NSObject<SKPaymentTransactionObserver>

In the class we have implemented the following methods:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error

The way our restore process works is that if you tap on the button that allows you to download all we simply run the restoreCompletedTransactions code as follows:

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

However, the callback, restoreCompletedTransactionsFailedWithError, which has been implemented in the store observer, does not always get called when we try to cancel the request. This happens when you boot the iPhone / iPod and try this for the first time. If you after that restart the app everything works fine.

The StoreObserver class is created when our app is launched, just by running the following code:

pStoreObserver = [[StoreObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:pStoreObserver]; 

Has anyone else had any similar experiences? Or does anyone have any suggestions on how to solve this? As I said, in the sandbox environment everything was working fine, no issues whatsoever, but now once it's gone live we're experiencing these.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk-3.0