在iOS 7中,在SKPaymentTransaction类上,属性transactionReceipt
:
// Only valid if state is SKPaymentTransactionStatePurchased.
@property(nonatomic, readonly) NSData *transactionReceipt
...是deprecated。但是,在我的代码中,我创建了一个InAppPurchase类,并且在我控制方法购买的方法中,我在代码中使用委托方法,它就像:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
// code and bla bla bla
[self initPurchase];
NSLog(@"PASO 1");
break;
case SKPaymentTransactionStatePurchased:
// this is successfully purchased!
purchased = TRUE;
NSLog(@"PASO 2");
[self isPurchased];
NSLog(@"purchased %s", purchased? "true" : "false");
// and return the transaction data
if ([delegate respondsToSelector:@selector(successfulPurchase:restored:identifier:receipt:)])
[delegate successfulPurchase:self restored:NO identifier:transaction.payment.productIdentifier receipt:transaction.transactionReceipt];
// and more code bla bla bla
break;
case SKPaymentTransactionStateRestored:
// and more code bla bla bla
[self restorePurchase];
NSLog(@"PASO 3");
break;
case SKPaymentTransactionStateFailed:
// and more code bla bla bla
[self failedNotification];
NSLog(@"PASO 4");
break;
//------------------------------------------//
// THANKS GUYS //
// GRETTINGS FROM BOLIVIA //
// ROCK ON!!!! n_n' //
//------------------------------------------//
}
}
}
答案 0 :(得分:27)
您可以将收据作为mainBundle的appStoreReceiptURL的内容。您可以找到参考资料:developer.apple.com
这是未经测试的代码,但在我的头脑中,我会说一些类似的话:
[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]
应该得到与transactionReceipt用于返回的结果相同的结果。
答案 1 :(得分:2)
万一有人也可能对这个问题感到困惑(也许你还读了一个像我这样有点过时的教程......)
请结帐WWDC 2014 Session 305使用收据防止未经授权的购买。它涵盖iOS和OS X,清晰而全面。