Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix promise not resolving on IOS14 #1064

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)
}
}
if (product) {
NSString *key = RCTKeyForInstance(product.productIdentifier);
[self addPromiseForKey:key resolve:resolve reject:reject];
[self addPromiseForKey:product.productIdentifier resolve:resolve reject:reject];

SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
Expand Down Expand Up @@ -190,8 +189,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)
}
}
if (product) {
NSString *key = RCTKeyForInstance(product.productIdentifier);
[self addPromiseForKey:key resolve:resolve reject:reject];
[self addPromiseForKey:product.productIdentifier resolve:resolve reject:reject];

payment = [SKMutablePayment paymentWithProduct:product];
#if __IPHONE_12_2
Expand Down Expand Up @@ -402,7 +400,6 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans
case SKPaymentTransactionStateFailed:
NSLog(@"\n\n\n\n\n\n Purchase Failed !! \n\n\n\n\n");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSString *key = RCTKeyForInstance(transaction.payment.productIdentifier);
dispatch_sync(myQueue, ^{
if (hasListeners) {
NSString *responseCode = [@(transaction.error.code) stringValue];
Expand All @@ -415,7 +412,7 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans
];
[self sendEventWithName:@"purchase-error" body:err];
}
[self rejectPromisesForKey:key code:[self standardErrorCode:(int)transaction.error.code]
[self rejectPromisesForKey:transaction.payment.productIdentifier code:[self standardErrorCode:(int)transaction.error.code]
message:transaction.error.localizedDescription
error:transaction.error];
});
Expand Down Expand Up @@ -464,7 +461,7 @@ -(void)purchaseProcess:(SKPaymentTransaction *)transaction {
pendingTransactionWithAutoFinish = false;
}
[self getPurchaseData:transaction withBlock:^(NSDictionary *purchase) {
[self resolvePromisesForKey:RCTKeyForInstance(transaction.payment.productIdentifier) value:purchase];
[self resolvePromisesForKey:transaction.payment.productIdentifier value:purchase];

// additionally send event
if (self->hasListeners) {
Expand Down