views:

908

answers:

3

Hi guys. Here's my problem :

When using storekit for in-app purchase, i'm displaying a "loading" view to tell the user to wait for a few seconds while the process is in progress; but let's say this same user, when the storekit ask him for his itunes account password, press the "cancel" button... How can i "catch" this event in order to hide the loading view?

I'm afraid it could be a cause of rejection for Apple since user's communication is pretty important.

Thanks for any tips!

Edit : I'm not in a transaction here; my first step is to restore completed transactions so the password prompt is trigger by this method :

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]
A: 

If the user clicks the cancel button then request will fail - use a store observer like so...

MyStoreObserver *observer = [[MyStoreObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

And handle like this....

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    }
}
Chris Beeson
My resquest doesn't fail because the first step in my process is to restore completed transactions using the [[SKPaymentQueue defaultQueue] restoreCompletedTransactions] method. But clicking "Cancel" during this process doesn't trigger any particular event (or non i can figure yet)
Vivi
+2  A: 

Something similar was reported in the Apple dev forums.

What happens when user hits Cancel after asking to restore......

In their case, a copy-and-paste of a method from the documentation created a bug that apparently compiled without error.

// wrong, but compiles
- (void)paymentQueue:(SKPaymentQueue *)queuerestoreCompletedTransactionsFailedWithError:(NSError *)error

instead of

// correct
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error

If your observer method looks like the first one above, then you're probably not receiving the failure message for the restore operation.

Update:

In SDK documentation for SKPaymentTransactionObserver, I see the restore failure method for OS 3.1 (2009-11-17) but 3.0 documentation (2009-05-01) doesn't seem to have it. Strange since the 3.1 doc states this observer method is "Available in iPhone OS 3.0 and later".

To be sure. I checked my copy of iPhoneOS3.0.sdk/System/Library/Frameworks/StoreKit.framework/Headers/SKPaymentQueue.h to make sure the restore failure observer method is there. (It is.)

otto
you usually see a call to restoreCompletedTransactionsFailedWithError when the user hits cancel. and sometimes it even is a SKErrorPaymentCanceled error code which makes hiding the error message easier. There are many cases when the user can hit cancel that will result in other error codes. Enjoy.
Carl Coryell-Martin
This was the issue :) Thanks guys.
Vivi
A: 

does anyone on this planet still yet have an answer to this unforgiving error for when a user hits cancel for:

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]

this is beyond me how apple can still allow this to happen. what am i suppose to do, just allow the pop up to occur whenever it wants! this is outragous!

Joshua