saurabh
saurabh

Reputation: 31

ios inapp purchase receipt

ios in-app purchase how to know this product has been purchased already ( i can check this by nsuserdefault locally but how to know after remove app from phone then re-install app )

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1

Upvotes: 0

Views: 187

Answers (1)

guidev
guidev

Reputation: 2885

You can the receipt in this way (from Read the Receipt Data):

// Load the receipt from the app bundle.
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) { /* No local receipt -- handle the error. */ }

If the user deleted the app, you have to provide a way to restore the purchase.

You can do something like this:

- (IBAction)restorePurchase:(id)sender{
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

// Then this is called
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init];

    for (SKPaymentTransaction *transaction in queue.transactions) {
        NSString *productID = transaction.payment.productIdentifier;
        [purchasedItemIDs addObject:productID];
        NSLog(@"product id is %@", productID);
    }  
}

Upvotes: 1

Related Questions