In App Purchase does not change its state to SKPaymentTransactionStatePurchased

无人久伴 提交于 2019-12-24 00:47:15

问题


I have added in app purchase feature to my iphone-ipad application and it is working in app store right now. I am updating this app and using method below to get transaction State notification

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        NSLog(@"Payment Queue");
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"Payment not finished");
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                break;
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Trying To Purchase");
                break;
            default:
                NSLog(@"Buraya giriyor");
                break;
    }
}

}

but the problem is when i try to connect to sandbox servers i get transaction failed state. Everything is the same with the working one in the app store. I just updated some views in the app. While using the app in the store it asks about AppleID and asks for a confirmation to download content. While i was testing in app purchase it was also asking for this AppleID and confirmation. But now, although it finds and gets the product identifiers it does not ask for these confirmations.



Fri Jan 9 04:14:19 iPod-touch CCDergi[1740] : indirilenappkey = 201107

The log info between two lines belong to the product that i am trying to buy.


Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : ----------------------------------------------

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Product title: Call Center Life Issue 8

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Product description: Issue 8 of the Call Center Life Magazine

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Product price: 2.99

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Product id: com.selvitech.cclife.201107

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : ----------------------------------------------

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Purchase Dergi

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Payment Queue

Fri Jan 9 04:14:21 iPod-touch CCDergi[1740] : Trying To Purchase

Fri Jan 9 04:14:25 iPod-touch CCDergi[1740] : Payment Queue

Fri Jan 9 04:14:25 iPod-touch CCDergi[1740] : Payment not finished



What may be the problem? What is it that I am missing?

Thank you in advance..


回答1:


**(Cancel that.. this didn't work for me, though it may still be helpful for others)

I noticed transactionReceipt method is not available on iOS9. It return nil value instead of a receipt data. So some apps using this method fail in purchase. This method is deprecated since iOS7. At last It became not working.

    NSData receipt = [transaction transactionReceipt]; //always return nil on ios9  

You should use [NSBundle appStoreReceiptURL] to get receipt data.

    NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];  
    NSData* receipt = [NSData dataWithContentsOfURL:url]; //works fine. 

I will update once I try to integrate this into my App for testing.



来源:https://stackoverflow.com/questions/7026630/in-app-purchase-does-not-change-its-state-to-skpaymenttransactionstatepurchased

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!