Pushwoosh / pushwoosh-react-native-plugin

Other
58 stars 44 forks source link

'pushOpened' isn't always fired #60

Closed JanithaR closed 5 years ago

JanithaR commented 5 years ago

I have a requirement where I must direct the user to a single screen nested in the navigation (react-navigation) based on the userdata I receive over the push notification. I have the following code in my App.js file.

DeviceEventEmitter.addListener('pushOpened', (e) => {
    const { userdata } = e;

    if (userdata) {
        const {
            ...
        } = userdata;

        if (...) {
            let type;

            if (Type === 1) {
                ...
            } else if (Type === 2) {
                ...
            }

            if (type) {
                NavigationService.navigate('...', { item: { ... }, type });
            }
        }
    }
});

My problem does not lie in the code, it lies where this event not being fired at random and I cannot figure out a reason why.

JanithaR commented 5 years ago

I've started to notice that 'pushReceived' also isn't firing every time.

JanithaR commented 5 years ago

Looking at the adb logcat output I see that native events are firing correctly all the time but they are not reflected in JS. Such as this,

05-02 11:49:32.163 10174 10522 I Pushwoosh: [RequestManager] 
05-02 11:49:32.163 10174 10522 I Pushwoosh: x
05-02 11:49:32.163 10174 10522 I Pushwoosh: |     Pushwoosh request:
05-02 11:49:32.163 10174 10522 I Pushwoosh: | Url: https://....api.pushwoosh.com/json/1.3/messageDeliveryEvent
05-02 11:49:32.163 10174 10522 I Pushwoosh: | Payload: {"request":{"application":"...","hwid":"...","v":"5.13.2","device_type":3,"userId":"...","hash":">z"}}
05-02 11:49:32.163 10174 10522 I Pushwoosh: | Response: {"status_code": 200, "status_message": "OK", "response": null}
05-02 11:49:32.163 10174 10522 I Pushwoosh: x
05-02 11:49:32.163 10174 10522 D Pushwoosh: [RequestManager] messageDeliveryEvent response success

And this is supposed to trigger,

DeviceEventEmitter.addListener('pushReceived', (e) => {
    if (__DEV__) console.log(...logHelper.logInfo(TAG, '======='));
    if (__DEV__) console.log(...logHelper.logInfo(TAG, 'push received; ', new Date()));
    if (__DEV__) console.log(...logHelper.logInfo(TAG, 'data; ', e));
    if (__DEV__) console.log(...logHelper.logInfo(TAG, '======='));
});

but not.

wfhm commented 5 years ago

Hello @JanithaR,

Is the issue related to Android only or does it affect iOS as well?

pushOpened event is triggered only when a user clicks on a push notification. pushReceived event fires when a push is received in foreground, and also fires when the app is brought to foreground when opening a push.

Could you please confirm that pushOpened event always fires when opening a push notification? Also, by any chance could you please provide us with a reproducer .apk (and .ipa if it affects iOS as well)? You can send it to our support team with a reference to this issue and they will pass it to the SDK team.

JanithaR commented 5 years ago

Thanks for getting back. Give me a few hours to come up with a more detailed reply when I'm in the office.

JanithaR commented 5 years ago

Hi, sorry for the long pause.

Yes, this seems to happen for both iOS and Android. What I have observed is very inconsistent. (All instances are triggered by sending a test push notification from the Pushwoosh control panel.)

I'm not sure how I can provide a separate reproducible application. If you have any suggestions please let me know.

wfhm commented 5 years ago

@JanithaR

We have thoroughly tested pushOpened and pushReceived callbacks behavior, and it works just as expected on our side - pushOpened is correctly called when a notification is opened both on iOS and Android. pushReceived is fired on Android instantly regardless of whether the app is in foreground, background or if it is closed; on iOS it is fired automatically when the app is in foreground, and it is fired when you open your app by clicking on a notification when the app is in background.

At this point we cannot proceed with the investigation since we cannot reproduce the issue at all.

If you cannot provide us with a reproducer, it would still be really great if you could provide us with device console logs which describe any suspicious behavior.

JanithaR commented 5 years ago

@wfhm I have resorted to deep linking to resolve the problems I had and it seems to work well but what you say and what I experienced is the polar opposite. I will try to provide a reproducer.

wfhm commented 5 years ago

@JanithaR

Sure, we look forward to hearing from you!

JanithaR commented 5 years ago

Guys, please close this, no need to keep it open.

By implementing deep linking I have resolved the use case where I must direct a user to a specific screen based on the data I receive via a push notification. This works for perfectly fine and I strongly believe that deep linking is the best way to do this.

For future reference, to anyone who would have difficulty implementing this use case and if you're using react-navigation just go on straight and implement deep linking. https://reactnavigation.org/docs/en/deep-linking.html

Edit: I do have another question which I would ask in a separate issue.

SchneiderOr commented 5 years ago

im facing exactly the same issues, pushReceived is working as expected, pushOpened not fired on android but fires inconsistently in iOS, we solve the navigation using deep linking as well, but its a workaround and we need the push event data...

we're using "pushwoosh-react-native-plugin": "^5.15.2",

JanithaR commented 5 years ago

In my opinion, deep linking is the best way to go about this. I found it to be working 100% every time on both iOS and Android, plus, having deep linking enabled in your app gives you other benefits such as letting users open specific content based on URLs.

You can most certainly access your push event data if you're using react-navigation. That's what I have done.

Here's how I extract the data that I want.

router

const HomeStack = createStackNavigator({
    ...
    DetailScreen: {
        screen: DetailScreen,
        path: 'detail/:data1&:data2'
    },
    ...
}

In the DetailScreen (deep linked) component,

 const data1 = navigation.getParam('data1', '');
 const data2= navigation.getParam('data2', '');

Test by creating a deep link in the Pushwoosh control panel and sending a push notification with that deep-link to the test devices. (Send Push -> Action -> Choos deep link ) scheme://home/detail/059fe5a7-d9d6-4ec5-88a8-46215103320c&Task

When you have everything working tell the web API team to update the Pushwoosh API /createMessage call with link

And here's a little something extra to ease your life by testing deep linking completely locally, Android adb shell am start -W -a android.intent.action.VIEW -d scheme://home/detail/$data1\&$data2 [you_app_package]

iOS xcrun simctl openurl booted $formatted scheme://home/detail/$data1&$data2