base64EncodedStringWithOptions for receipt data re

2019-07-04 02:39发布

I want to validate my in app purchases using server side. So I use the following code:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction * transaction in transactions) {

        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
            {
                NSData *reciptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
                if(reciptData) {
                    NSDictionary *parameters = @{@"receipt_data" : [reciptData base64EncodedStringWithOptions:0]};//App crashes here -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
                }
            }
                break;

            default:
                break;
        }
    };
}

The weirdest thing is that application crashes on one iPad with iOS 8.0.2 and does not crash on other with the same iOS version.

The worst thing is that I do not have access to device on which application crashes.

As far as I understand - base64EncodedStringWithOptions: returns nil but I don't know why.

Can anyone help me?

1条回答
迷人小祖宗
2楼-- · 2019-07-04 03:04

I have seen this empty receipt issue before where devices are running some form of in-app purchase cracking program such as "IAP Free" or "IAP Cracker" which implies the device has been jailbroken and an in-app purchase cracking tool has been installed. I would make sure the device where the application crashes is not running some form of in-app purchase cracking tool. The other thing you can do is ignore an empty receipt - but don't return any goods to avoid the crash or return a good that is only available locally. This depends on how you want to react to someone cracking in-app purchases - sometimes it's good to pretend it all works locally but limit features from your server.

查看更多
登录 后发表回答