Reputation: 31
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 )
Upvotes: 0
Views: 187
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