11#import " RNIapIos.h"
2+ #import " IAPPromotionObserver.h"
23
34#import < React/RCTLog.h>
45#import < React/RCTConvert.h>
56
67#import < StoreKit/StoreKit.h>
78
89// ////////////////////////////////////////////////// _//////////_ // Private Members
9- @interface RNIapIos () {
10+ @interface RNIapIos () <IAPPromotionObserverDelegate> {
1011 NSMutableDictionary *promisesByKey;
1112 BOOL autoReceiptConform;
1213 SKPaymentTransaction *currentTransaction;
1314 dispatch_queue_t myQueue;
1415 BOOL hasListeners;
15- SKProduct *promotedProduct;
16- SKPayment *promotedPayment;
1716}
1817@end
1918
@@ -24,6 +23,7 @@ -(instancetype)init {
2423 if ((self = [super init ])) {
2524 promisesByKey = [NSMutableDictionary dictionary ];
2625 [[SKPaymentQueue defaultQueue ] addTransactionObserver: self ];
26+ [IAPPromotionObserver sharedObserver ].delegate = self;
2727 }
2828 myQueue = dispatch_queue_create (" reject" , DISPATCH_QUEUE_SERIAL);
2929 validProducts = [NSMutableArray array ];
@@ -49,6 +49,7 @@ - (void)stopObserving {
4949- (void )addListener : (NSString *)eventName {
5050 [super addListener: eventName];
5151
52+ SKPayment *promotedPayment = [IAPPromotionObserver sharedObserver ].payment ;
5253 if ([eventName isEqualToString: @" iap-promoted-product" ] && promotedPayment != nil ) {
5354 [self sendEventWithName: @" iap-promoted-product" body: promotedPayment.productIdentifier];
5455 }
@@ -89,6 +90,14 @@ -(void)rejectPromisesForKey:(NSString*)key code:(NSString*)code message:(NSStrin
8990 }
9091}
9192
93+ // ////////////////////////////////////////////////// _//////////_ // IAPPromotionObserverDelegate
94+ - (BOOL )shouldAddStorePayment : (SKPayment *)payment forProduct : (SKProduct *)product {
95+ if (hasListeners) {
96+ [self sendEventWithName: @" iap-promoted-product" body: product.productIdentifier];
97+ }
98+ return NO ;
99+ }
100+
92101// ////////////////////////////////////////////////// _//////////_// EXPORT_MODULE
93102RCT_EXPORT_MODULE ();
94103
@@ -209,11 +218,13 @@ -(void)rejectPromisesForKey:(NSString*)key code:(NSString*)code message:(NSStrin
209218RCT_EXPORT_METHOD (promotedProduct:(RCTPromiseResolveBlock)resolve
210219 reject:(RCTPromiseRejectBlock)reject) {
211220 NSLog (@" \n\n\n *** get promoted product. \n\n ." );
221+ SKProduct *promotedProduct = [IAPPromotionObserver sharedObserver ].product ;
212222 resolve (promotedProduct ? promotedProduct.productIdentifier : [NSNull null ]);
213223}
214224
215225RCT_EXPORT_METHOD (buyPromotedProduct:(RCTPromiseResolveBlock)resolve
216226 reject:(RCTPromiseRejectBlock)reject) {
227+ SKPayment *promotedPayment = [IAPPromotionObserver sharedObserver ].payment ;
217228 if (promotedPayment) {
218229 NSLog (@" \n\n\n *** buy promoted product. \n\n ." );
219230 [[SKPaymentQueue defaultQueue ] addPayment: promotedPayment];
@@ -318,18 +329,6 @@ -(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWi
318329 NSLog (@" \n\n\n restoreCompletedTransactionsFailedWithError \n\n ." );
319330}
320331
321- - (BOOL )paymentQueue : (SKPaymentQueue *)queue shouldAddStorePayment : (SKPayment *)payment forProduct : (SKProduct *)product {
322- NSLog (@" \n\n\n *** should add store payment. \n\n ." );
323- promotedProduct = product;
324- promotedPayment = payment;
325-
326- if (hasListeners) {
327- [self sendEventWithName: @" iap-promoted-product" body: payment.productIdentifier];
328- }
329-
330- return NO ;
331- }
332-
333332-(void )purchaseProcess : (SKPaymentTransaction *)transaction {
334333 if (autoReceiptConform) {
335334 [[SKPaymentQueue defaultQueue ] finishTransaction: transaction];
0 commit comments