Notificare / notificare-demo-react-native

Demo App for Notificare using the React Native Module
1 stars 0 forks source link

Android: onNotificationOpenRegistered tries to access bridge before bridge is initialized #1

Open jariz opened 7 years ago

jariz commented 7 years ago

Description: When the app was started from a notification (i.e., it's not running yet), it will attempt to call onNotificationOpenRegistered in NotifcareReceiver, which will then try to initialize a WritableMap. This won't work however (it'll fail with 'SoLoader.init() not yet called'), because the bridge with react native isn't initialized yet, and neither is NotificareEventEmitter.

Possible solution: Checking if the bridge exists before trying to dispatch the event.
Then, either wait for the bridge to start up, or just abort trying to dispatch the event.

Bug replication: You can replicate this issue fairly easy by just running an app that uses the SDK, closing the application, sending a notification (with a deep link), and then clicking said notification.

See also: facebook/react-native#10379

silentjohnny commented 7 years ago

Hi Jari,

The onNotificationRegistered is only called when you open the notification from your ReactJS app. Did you test this with the code that is used in this demo app or with your own code? Can you send me a code snippet and your Android manifest if this is the case, it would make it a lot easier to see why this happens, because I can not replicate with this demo app.

jariz commented 7 years ago

I fixed it by creating my own intent receiver that doesn't override onNotificationOpenRegistered. (luckily I don't handle this event in my project) I do still believe this is a bug in the RN lib though, I'll try to create an example project that can recreate this issue. It appears to be related to the fact that my application handles a url protocol, which the notification launches. (which isn't that uncommon, I'm sure) EDIT: Also, apologies for posting this issue on the wrong project, just noticed this is the demo app. 😅

silentjohnny commented 7 years ago

If the notification you sent contains a URL to open, that would indeed explain because this is totally handled by the native DefaultIntentReceiver which doesn't have any knowledge of React being present or not. This will be fixed in an update of the library. We are still porting more features of the native libraries to the React lib anyway.