已在StoreKit中购买订阅
我在iOS应用中使用应用内购买的可更新订阅。 当用户尝试购买他们已经为消息付费的订阅时,iTunes会显示“您当前订阅了此信息”。已在StoreKit中购买订阅
如何检测此事件何时发生,以便我可以处理事务并授予对我的应用程序的访问权限。
在paymentQueue:updatedTransactions:它作为SKPaymentTransactionStateFailed传入的观察者的方法。我如何区分这种类型的故障和其他故障,如用户按取消按钮?
我是否会提交已返回的事务或是否需要调用restorePreviousTransactions。
在Apple文档中,它声明“如果用户试图购买非消费品或已购买的可续订订阅,您的应用程序会收到该项目的常规交易,而不是恢复交易。但是,用户不会再为该产品收取费用,您的应用程序应将这些交易视为与原始交易相同。“
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];
玩完交易
我希望这有助于