robotmedia / RMStore

A lightweight iOS library for In-App Purchases
Apache License 2.0
2.43k stars 450 forks source link

Canceling In-App Purchase Throws Wrong Exception #143

Open ccocchiaro opened 9 years ago

ccocchiaro commented 9 years ago

When a user is prompted to continue an In-App Purchase they initiate, canceling it throws the wrong exception ("Cannot connect to iTunes Store"), so the app has no way of knowing whether to report it to the user or not. The following exception below is being thrown but a more appropriate one should be used when canceling a transaction.

RMStore: transaction failed with product TCM_KC_ADD3STUDENTS and error Error Domain=SKErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo=0x17407b740 {NSLocalizedDescription=Cannot connect to iTunes Store}

msmollin commented 9 years ago

This seems to actually be a bug in StoreKit.

- (void)didFailTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue error:(NSError*)error

is being called correctly from the result of SKPaymentTransactionObserver in - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

which contains a value of SKPaymentTransactionStateFailed when you tap cancel.

I can confirm this happens on iOS 8.2 on device as well. Haven't upgraded my device yet to 8.3, but judging from the patch notes they probably didn't fix it there either. If you have time, I'd open a Radar and link it back here.

pahnev commented 9 years ago

You can check what error code the transaction is returning

if (transaction.error.code == SKErrorPaymentCancelled) {
    NSLog(@"user cancelled");
}  else {
    // Some other error you can show to user
}
msmollin commented 9 years ago

@pahnev good call. That appears to work, although wow the localized description is REALLY not aligned with that enum naming convention.