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.
時,通過與蘋果的驗證(我用的php網站的代碼來做到這一點),你會得到一個「身份碼」迴響應,並可以驗證它是否是一個代碼21006(訂閱是存在訂閱,檢測已過期)或其他人(我認爲除0和21006以外的任何內容都是實際的錯誤)。
我做事情的方式是將交易詳細信息存儲在PLIST文件中,該文件存儲在文檔目錄中。
你可以到PLIST添加額外的領域,如expiryDates,布爾標誌等
這種方式,你有收據的複印件,但你應該總是驗證它,因爲它可能已過期。
Q:在paymentQueue:updatedTransactions:它 即將通過作爲SKPaymentTransactionStateFailed觀察者的方法。我如何 區分這種類型的故障和其他故障,如 用戶按取消按鈕?
在updatedTransactions方法中使用switch語句來確定不同類型的響應。
例
-(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:
// take action whilst processing payment
break;
case SKPaymentTransactionStatePurchased:
// take action when feature is purchased
break;
case SKPaymentTransactionStateRestored:
// take action to restore the app as if it was purchased
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled)
{
// Do something with the error
} // end if
break;
default:
break;
} // end switch
} // next
的TransactionStateFailed處理失敗,雖然我不代碼取消,因爲沒有理由讓我在我的應用程序這樣做。
問:我是否提交退回的交易或是否需要致電 restorePreviousTransactions。
我相信StoreKit處理這種在內部與finishTransaction方法和restorePreviousTransaction方法
即
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
玩完交易
我希望這有助於