在iOS 7警告中不推荐使用transactionreceipt的问题

时间:2013-09-25 15:37:14

标签: iphone ios objective-c in-app-purchase ios7

我要更新我的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];
        }
    }

我该如何解决这个问题?

// EDITED:

我使用了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]购买faild ......

- (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];
    }
}

1 个答案:

答案 0 :(得分:3)

类似的东西:

NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt;
receipt = [NSData dataWithContentsOfURL:receiptUrl];