Q: How I can detect when this event (currently subscribed) has occurred so that I can process the transaction and grant access to my app.
You discover when a subscription exists through verification with Apple (I use the php website code for this), you get a βstatus codeβ response and you can check if it is 21006 (the subscription has expired), or others ( I believe that everything except 0 and 21006 is an actual error).
As I do things, I store transaction data in a PLIST file, which I store in the document directory.
You can add additional fields to PLIST, such as expiryDates, boolean flags, etc.
Thus, you have a copy of the receipt, although you should always check it, because it may have expired.
Q: In paymentQueue: updatedTransactions: the observer method passes through SKPaymentTransactionStateFailed. How can I distinguish between this type of failure and other failures, such as the user presses the cancel button?
You use the switch statement in the updatedTransactions method to define different types of responses.
Example
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error { NSString *message = [NSString stringWithFormat:@"Transaction failed with error - %@", error.localizedDescription]; NSLog(@"Error - %@", message); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; } -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { NSLog(@"updatedTransactions"); for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchasing:
TransactionStateFailed handles crashes, although I do not code to cancel, as there is no reason for this in my application.
Q: I am sending a transaction that is being returned or I need to call restorePreviousTransactions.
I believe that StoreKit handles this internally with the endTransaction method and restorePreviousTransaction methods
t
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
complete transactions
I hope this helps