Brave Heart
Brave Heart

Reputation: 517

Check if app was bought

I just wanted to ask if there is a way to check if the user actually did buy an app programmatically. I saw how Infinity Blade 3 and other games forced the user to log in to their apple accounts and somehow checked with the store on whether or not the app has been bought. How is this possible to create programmatically? I've searched all over the web just to find how to open up the storkit view from which you can purchase other apps or videos, etc... Thanks in advance

Upvotes: 2

Views: 2285

Answers (1)

Moshe Gottlieb
Moshe Gottlieb

Reputation: 4023

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.

Upvotes: 6

Related Questions