我要为 iOS 7 更新我的应用程序并且我正在使用 IAP,但是 xcode 5 给了我这个错误:
不推荐使用 transactionreceipt :首先在 iOS 7 中不推荐使用
这是我的代码:
// saves a record of the transaction by storing the receipt to disk
- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
if ([transaction.payment.productIdentifier isEqualToString:kProductIdentifier])
{
// save the transaction receipt to disk
[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
我该如何解决这个问题?
//编辑:
我使用了 AndreyMan 的答案,但什么也没发生,编译器给了我 APP:requestProductData END 消息
- (void)requestProductData
{
[NSThread sleepForTimeInterval:2];
NSLog(@"IN-APP:requestProductData");
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers: [NSSet setWithObject: @"com.compony.product"]];
request.delegate = self;
[request start];
NSLog(@"IN-APP:requestProductData END");
}
然后给我这些信息:
2013-10-08 14:26:21.400 Arta[1138:60b] Purchasing... 2013-10-08 14:26:28.380 Arta[1138:60b] Unknown Reason. 2013-10-08 14:26:28.383
Arta[1138:60b] 购买失败...
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
NSLog(@"Purchase compelete...");
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
NSLog(@"Purchase faild...");
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
NSLog(@"Restore compelete...");
break;
case SKPaymentTransactionStatePurchasing:
NSLog(@"Purchasing...");
break;
default:
break;
}
}
}
- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
// error!
[self finishTransaction:transaction wasSuccessful:NO];
if (transaction.error.code == SKErrorClientInvalid) {
}
else if (transaction.error.code == SKErrorPaymentInvalid) {
}
else if (transaction.error.code == SKErrorPaymentNotAllowed) {
}
else if (transaction.error.code == SKErrorPaymentCancelled) {
// [self showAlert:@"In-App Purchase" withMessage:@"This device is not allowed to make the payment."];
NSLog(@"User Cancellation.");
}
else {
// SKErrorUnknown
NSLog(@"Unknown Reason.");
}
}
else {
// this is fine, the user just cancelled, so don’t notify
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
}