OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 373 forks source link

removeTriggerForKey and getTriggerValueForKey are not working for in app message in react-native #935

Closed rajatgalav closed 4 years ago

rajatgalav commented 4 years ago

I installed onesignal using command npm install react-native-onesignal@^3.5.0 It installed version 3.6.2

Everything is working except when trying to removeTriggerForKey key is not removed. I am able to add the trigger and in app message is shown but when i click on it i am trying to remove the key. But it is not working.

Also getTriggerValueForKey is also not working.

rgomezp commented 4 years ago

Howdy, Can you please include a code example?

rajatgalav commented 4 years ago

Fiirst i imported the onesignal library in my component. import OneSignal from 'react-native-onesignal';

then added event listener in componentDidMount and removed it in componentWillUnmount

componentDidMount() {
        OneSignal.removeTriggerForKey("level");
        OneSignal.addEventListener('inAppMessageClicked', this.onInAppClicked);
 }
componentWillUnmount() {
        OneSignal.removeEventListener('inAppMessageClicked', this.onInAppClicked);
 }

for onInappClicked i wrote

onInAppClicked = (action) => {
        OneSignal.getTriggerValueForKey("level", function (value) {
            console.log("level:==>", value)
        });
        console.log('in app action is=>>', action)
        const {click_name} = action
        OneSignal.removeTriggerForKey("level");
        this.props.navigation.navigate(click_name)
}

and onclick of a button i write

OneSignal.addTrigger("level", true);
OneSignal.getTriggerValueForKey("level", function (value) {
      console.log("level:==>", value)
});

Howdy, Can you please include a code example?

rajatgalav commented 4 years ago

I used setLogLevel to log the errors. It is prompting error ERROR In-App message with id ' ////// ' already displayed or is already preparing to be display!

mikechoch commented 4 years ago

@rajatgalav I am not able to reproduce this issue you are having. I even implemented the example you showed here and nothing seemed to be wrong. Are you experiencing this in Android, iOS, or both?

Also setLogLevel VERBOSE will show you all OneSignal logs, so try this: setLogLevel(6, 0)

And just to clarify this In-App message id was not actually '//////', right?

rajatgalav commented 4 years ago

@mikechoch right now i am trying it in android, not sure about ios. setLogLevel(6, 0) it was not working so i changed it to setLogLevel(0, 6). Does setLogLevel(6, 0) this show logs on browser console ? Yes '////////' it was not shown in the message. Their was and id of numbers. Also i think

OneSignal.addTrigger("level", true);
OneSignal.getTriggerValueForKey("level", function (value) {
      console.log("level:==>", value)
});

these statements does not work sequentially.

When i checked node modules getTriggerValueForKey does not accept callback function.

rajatgalav commented 4 years ago

@rgomezp getTriggerValueForKey is returning '' empty string. It should return null value if the trigger is not added, according to the documentation.

rgomezp commented 4 years ago

Thanks for the catch. We will update the documentation to reflect the correct return value. Enjoy!

tyson90 commented 3 years ago

Documentation says method getTriggerValueForKey accepts callback as a second argument, while this method really returns a Promise and accepts only one argument. This should be fixed in docs.