Check if app was bought

谁说胖子不能爱 提交于 2019-12-04 16:16:32

You could try to check for the app's receipt and verify it with the AppStore -

NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL]; // iOS 7+, do not use respondsToSelector as it will report YES for iOS 6 too

Here's Apple's documentation on how to verify your receipt.
If the receipt is nil or the url points to a non existent path, you may need to refresh the receipt.
Implement SKRequestDelegate and check:

NSError* err = nil;
if (![url checkResourceIsReachableAndReturnError:&err]){
    SKReceiptRefreshRequest* request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
    request.delegate = self; /* or your delegate's instance here */
    [request start];
}
....
-(void)requestDidFinish:(SKRequest*)request{
    if([request isKindOfClass:[SKReceiptRefreshRequest class]]){
        // The URL should be available now, if it's not - I guess the app is cracked
    }
}
-(void)request:(SKRequest*)request didFailWithError:(NSError *)error{
    ; // This does not mean the app is pirated, use this to schedule the test for later.
}

I would disable these checks in debug mode (and on the simulator).
You may want to check this project - VerifyStoreReceiptiOS for verifying your receipts.

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