Skip to content

Commit

Permalink
added workaround for the watchOS bug where the sandbox receipt is sto…
Browse files Browse the repository at this point in the history
…red in the production location.
  • Loading branch information
aboedo committed Jun 19, 2020
1 parent 91745f1 commit 00e61a8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Purchases/Purchasing/RCReceiptFetcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@

@implementation RCReceiptFetcher : NSObject

- (NSData *)receiptData
{
- (NSData *)receiptData {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];

#if TARGET_OS_WATCH
// as of watchOS 6.2.8, there's a bug where the receipt is stored in the sandbox receipt location,
// but the appStoreReceiptURL method returns the URL for the production receipt.
// This code replaces "sandbox" with "receipt" as the last component of the receiptURL so that we get the
// correct receipt.
// This has been filed as radar FB7699277. More info in https://github.com/RevenueCat/purchases-ios/issues/207.
NSString *receiptURLFolder = [[receiptURL absoluteString] stringByDeletingLastPathComponent];
NSURL *productionReceiptURL = [NSURL URLWithString:[receiptURLFolder stringByAppendingPathComponent:@"receipt"]];
receiptURL = productionReceiptURL;
#endif

NSData *data = [NSData dataWithContentsOfURL:receiptURL];
RCDebugLog(@"Loaded receipt from %@", receiptURL);
return data;
Expand Down

0 comments on commit 00e61a8

Please sign in to comment.