diff --git a/InAppUtils/InAppUtils.m b/InAppUtils/InAppUtils.m index f382e75..23da39b 100644 --- a/InAppUtils/InAppUtils.m +++ b/InAppUtils/InAppUtils.m @@ -129,7 +129,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue callback(@[@"restore_failed"]); break; } - + [_callbacks removeObjectForKey:key]; } else { RCTLogWarn(@"No callback registered for restore product request."); @@ -204,6 +204,13 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue callback(@[@(canMakePayments)]); } +RCT_EXPORT_METHOD(hasReceipt:(RCTResponseSenderBlock)callback) +{ + NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; + BOOL hasReceipt = [[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]; + callback(@[@(hasReceipt)]); +} + RCT_EXPORT_METHOD(receiptData:(RCTResponseSenderBlock)callback) { NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; diff --git a/Readme.md b/Readme.md index 46b5757..69de5f8 100644 --- a/Readme.md +++ b/Readme.md @@ -111,7 +111,7 @@ InAppUtils.restorePurchases((error, response) => { Alert.alert('itunes Error', 'Could not connect to itunes store.'); } else { Alert.alert('Restore Successful', 'Successfully restores all your purchases.'); - + if (response.length === 0) { Alert.alert('No Purchases', "We didn't find any purchases to restore."); return; @@ -148,6 +148,7 @@ iTunes receipts are associated to the users iTunes account and can be retrieved ```javascript InAppUtils.receiptData((error, receiptData)=> { if(error) { + // Could also advice the user to restore purchases Alert.alert('itunes Error', 'Receipt not found.'); } else { //send to validation server @@ -157,6 +158,26 @@ InAppUtils.receiptData((error, receiptData)=> { **Response:** The receipt as a base64 encoded string. + +### Checking if receipt exists + +You can limit user login prompts by checking if the receipt exists before trying to read it. +Useful if you don't want a prompt for new users + +```javascript +InAppUtils.hasReceipt((exists) => { + if(exists) { + // Continue with receipt validation before prompting for restoring + InAppUtils.receiptData((error, receiptData)=> { + //... + }) + } +}); +``` + +**Response:** Exists boolean flag. + + ### Can make payments Check if in-app purchases are enabled/disabled.