PDA

View Full Version : updatedTransactions callback not working after iOS4.2




srenou
Nov 3, 2011, 08:06 AM
Hi,

We've been having a tricky problem with store kit. We are trying to implement correctly the in-app purchase renewable subscriptions process into an app that already is on the appStore with standard in-app purchase (non-consumable products) set up.

So far, and after spending 2 months fighting with the sandbox weird behavior, we came up with a working solution on a test iPad running iOS4.2.

Nasty surprise we got when testing this code on a iPad with 4.3 or 5.0, it does not have the same behavior.

We narrowed it down to this simple fact:
- iOS4.2 : the updatedTransactions callback is working properly
- iOS4.3 and above: the updatedTransactions callback is never called by the sandbox.

Any ideas on why a store kit code that works on iOS4.2 wouldn't work on following iOS versions? I didn't see anything deprecated on this.

Here is the code of our updatedTransactions code:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
NSLog(@"Add payment queue");
for(SKPaymentTransaction *transaction in transactions) {
NSLog(@"Transaction state: %d, %d, %d, %d", transaction.transactionState, SKPaymentTransactionStatePurchased, SKPaymentTransactionStateFailed, SKPaymentTransactionStateRestored);
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:

if([transaction.payment.productIdentifier isEqualToString:FM_PRODUCT_IDENTIFIER_SUBSCRIPTION]){
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:transaction.transactionReceipt forKey:@"TransactionReceiptOfTransaction"];
}

[self completeTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

break;

case SKPaymentTransactionStateFailed:
NSLog(@"%@", transaction.error);

[self failedTransaction:transaction];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"")
message:NSLocalizedString(@"Your subscription has expired.", @"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
SAFE_RELEASE(alert);

[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

if([transaction.error code] != SKErrorPaymentCancelled) {
if([transaction.payment.productIdentifier isEqualToString:FM_PRODUCT_IDENTIFIER_SUBSCRIPTION]){
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:transaction.transactionReceipt forKey:@"TransactionReceiptOfTransaction"];
}

}

break;

case SKPaymentTransactionStateRestored:

if([transaction.payment.productIdentifier isEqualToString:FM_PRODUCT_IDENTIFIER_SUBSCRIPTION]){
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:transaction.transactionReceipt forKey:@"TransactionReceiptOfTransaction"];
}

[self restoreTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

default:
NSLog(@"Other");
break;
}
}
}

Thanks,
Stephane



ArtOfWarfare
Nov 3, 2011, 08:56 AM
I see nothing wrong with your posted code (although it's possible I overlooked something.) I would suspect that your error exists elsewhere.

In my experience, writing the code for In-App purchases is the (relatively) easy part, and your issues rarely exist in the code, but instead they're often in trying to test it.

1.) Your IAP needs to have been submitted on iTunes Connect. I assume since that sometimes works, you've probably done that already.
2.) You need to be logged out of any iTunes store accounts on the test device (and I'm pretty sure the simulator won't work at all for testing IAPs.)
3.) You should log into your test account only when your app prompts you to. (and it should mention at the bottom of the notification something about the fact you're logging into the sandbox, not the real store.)

If it's not working, there's a good chance your test user account is corrupted and exists in some limbo between being a test user and a real user. Make a new test user and try with it.

srenou
Nov 3, 2011, 12:18 PM
I see nothing wrong with your posted code (although it's possible I overlooked something.) I would suspect that your error exists elsewhere.

In my experience, writing the code for In-App purchases is the (relatively) easy part, and your issues rarely exist in the code, but instead they're often in trying to test it.

1.) Your IAP needs to have been submitted on iTunes Connect. I assume since that sometimes works, you've probably done that already.
2.) You need to be logged out of any iTunes store accounts on the test device (and I'm pretty sure the simulator won't work at all for testing IAPs.)
3.) You should log into your test account only when your app prompts you to. (and it should mention at the bottom of the notification something about the fact you're logging into the sandbox, not the real store.)

If it's not working, there's a good chance your test user account is corrupted and exists in some limbo between being a test user and a real user. Make a new test user and try with it.

Hey,

I confirm that my IAP works well, as I do subscribe to it when using the app in IOS4.2. We do all our test with checking first that there are no user accounts set up in the store section of the iPad settings and we do have only tested this using iTunesConnect test user (we actually used over 100 different test users as renewable subscriptions burn the test user as soon it has a running subscription... damn sandbox...).

The weirdest thing is that updatedTransactions is called back ok on iOS4.2 and not in 4.3 and 5.0... Also we have an extra popup from store kit on the 4.3 and 5.0 asking right away after launch the iTunes account, when it does not ask that in 4.2. We think it's the instantiation of the Store Manager that triggers that popup, but it's weird that it's not doing it in 4.2...

Any ideas?
S/