React-native-iap: Promoted IAP listener not firing in 4.4.2? (working in 4.4.1)

Created on 6 Mar 2020  路  23Comments  路  Source: dooboolab/react-native-iap

Version of react-native-iap

4.4.2

Version of react-native

0.61.5

Platforms you faced the error (IOS or Android or both?)

IOS

Expected behavior

The 'iap-promoted-product' event listener fires when opening the app using a itms-services:// link.

Actual behavior

The 'iap-promoted-product' event listener does not fire.

Tested environment (Emulator? Real Device?)

Real Device. Iphone 7.

I had a working implementation of the promoted IAP workflow that stopped working once I upgraded to the 4.4.2 version. Sounds weird being a minor release, but downgrading solved the issue.

鈱氾笍 regression

All 23 comments

Thanks for sharing. The change is simple #938. I think we should revert this if this is causing a problem!

@cuttlas Can you also try this and come back?

not work for me also downgrade also not working but clicking the acual promo in appstore is working but app close and install production one instead T^T @hyochan

still doest work now i init new react-native project and test also not work

I'm facing the same problem :(

appstore keep rejecting me for 2 week now T^T can someone help

I'm facing the same problem :(

solve the lasted version have comment out
this part
// - (instancetype)init { // if ((self = [super init])) { // [SKPaymentQueue.defaultQueue addTransactionObserver:self]; // }

remove comment out it work like before :)

I'm facing the same problem :(

solve the lasted version have comment out
this part
// - (instancetype)init { // if ((self = [super init])) { // [SKPaymentQueue.defaultQueue addTransactionObserver:self]; // }

remove comment out it work like before :)

Many thanks, @punjasin. This piece of code is located in IAPPromotionObserver.m right?

Thanks for sharing the issue wonderful people~!
Followed by the StackOverflow this is actually recommended to be written in viewDidLoad to ensure that it's only called just once! There was an issue related to this and was removed in 4.4.2. I should have to provide the readme. Sorry for that 馃槥

Related #971

Hi @hyochan, so the final solution for this is to uncomment the above code and that's it or do I need to do anything else. I don't understand much about the viewDidLoad method that you mentioned, where can I find it, can you add a step by step here, many thanks :(

@nenjamin2405 You can find that in AppDelegate.m file in your react native project.

@hyochan Sorry but I cannot find viewDidLoad in my AppDelegate.m. The only thing available there is

 #import "IAPPromotionObserver.h"


[IAPPromotionObserver startObserving];

I don't know much about the native code of iOS.

@nenjamin2405 Sorry, I think I've talked too quickly. I've just fixed some code and added a guide to add IAPPromotionObserver properly in your app.

Try installing [email protected] and follow the code here.

Many thanks, @hyochan, will try it and let you know

Hi @hyochan, I've just tried the newest version and added the recommended code snippet, when I terminate the app, there is an error logged in Xcode:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[IAPPromotionObserver<0x1035c85a0> dealloc]: cannot dealloc a class object.'

image

@nenjamin2405 I think you don't need the dealloc. I'll change the readme. I've seen in StackOverflow. I'm not familiar with objc either 馃槥. It's bad.

Hi @hyochan, it's very weird that in version 4.4.4, I could receive an event from the listener of promoted purchaseIAPEmitter.addListener('iap-promoted-product'), however when the purchase is completed (via iap-promoted-product or RNIap.requestPurchase), the listener purchaseUpdatedListener will not receive any event until I kill and reopen the app. Then I updated to version 4.4.8, the IAPEmitter.addListener('iap-promoted-product') didn't work anymore, but the RNIap.requestPurchase and purchaseUpdatedListener worked fine. So which version should I use right now to leverage both promoted flow and normal RNIap.requestPurchase flow?

@nenjamin2405 Have you called initConnection in iOS in 4.4.8 before adding iap-promoted-product listener?

@hyochan Bingooo!!! That's what i'm missing. Previously the initConnection is available only in the component that containsRNIap.requestPurchase, now I moved it to the outermost before adding the iap-promoted-product listener so now it works, thank youu!

By the way, I saw that in version 4.4.8 you're commenting the snippet

- (instancetype)init {
  if ((self = [super init])) {
    [SKPaymentQueue.defaultQueue addTransactionObserver:self];
  }

  return self;
}

-(void) dealloc {
  [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
}

inside IAPPromotionObserver.m.

I need to uncomment them to make the whole flow working

@nenjamin2405 Ah! That's sad. I think we need to make IAPPromotionObserver and RNIap into one and share the same transaction observer. Since adding a transaction observer should be called just once to prevent other side effects as I've referred.

Since it feels like you have the debugging environment, would you like to contribute to this issue? I can reward you $30 for that in open-collective.

Hi @hyochan I'm not quite sure how can I contribute to this issue, can you explain more details

@nenjamin2405 The goal is to merge IAPPromotionObserver to RNIap file is iOS to call addTransactionObserver:self just once.

Below are the steps you can try.

  1. Look into node_modules/react-native-iap/ios
    image
  2. Try to solve the problem and test your codes.
  3. Fork react-native-iap and paste your codes.
  4. Delete IAPPromotionObserver.m and IAPPromotionObserver.h.
  5. Give a PR.

@hyochan I made PR #1039 for this issue based on the above comment.

Was this page helpful?
0 / 5 - 0 ratings