Closed killerchip closed 1 day ago
The API has changed in the 5.x version.
Try using
OneSignal.Notifications.addEventListener("permissionChange", enabled => {
console.log("Notifications Enabled: ", enabled)
})
You might have to re-build the native apk file as well.
Thanks, @Codesane for linking to the new method!
@killerchip please feel free to refer to our migration guide for an overview of all the changes in 5.0.0.
Let us know if you have any additional questions or concerns!
@jennantilla @Codesane My problem still remains... I don't even use the 'addEventListener', I just add the following lines in my App.tsx
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
OneSignal.initialize('XXXXX');
And I get the error.
I'm no Android expert, but I think the issue is somewhere there: indext.ts:
export function initialize(appId: string) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
RNOneSignal.initialize(appId);
_addPermissionObserver();
_addPushSubscriptionObserver();
}
The RNOneSignal.initialize
native function is supposed to initialize and run 'initWithContext'.
But either this does not happen, or there's a race condition, and 'initWithContext' is not called when the _addPremissionObserver()
is called.
Has my suspicion any logical base? or am I looking into the wrong direction?
In fact I added a couple of logging in the function above, and created a log files from 'adb logcat'.
I can see that the _appPermissionObserver()
is called before the initWithContext
is called on the native level, for some reason.
Thanks, @Codesane for linking to the new method!
@killerchip please feel free to refer to our migration guide for an overview of all the changes in 5.0.0.
Let us know if you have any additional questions or concerns!
@jennantilla Thanks for the info and can you add this info in the official docs
@killerchip I am not able to reproduce this issue. Which verison of the onesignal-expo-plugin and react-native-onesignal are you using?
@killerchip I am not able to reproduce this issue. Which verison of the onesignal-expo-plugin and react-native-onesignal are you using?
Hi @emawby , apologies for the late reply. I'm using react-native-onesignal: ^5.0.0 and onesignal-expo-plugin: ^2.0.0
and from my yan.lock I see that those versions exactly resolved.
Gettings Must call 'initWithContext' before use
crashes.
Using "react-native-onesignal": "^5.0.2",
useEffect(() => {
OneSignal.initialize(ONE_SIGNAL_APP_ID);
OneSignal.Notifications.addEventListener('click', async (e) => {
console.log('OneSignal: notification click event:', e);
});
}, []);
};
Gettings
Must call 'initWithContext' before use
crashes. Using "react-native-onesignal": "^5.0.2",useEffect(() => { OneSignal.initialize(ONE_SIGNAL_APP_ID); OneSignal.Notifications.addEventListener('click', async (e) => { console.log('OneSignal: notification click event:', e); }); }, []); };
Facing this issue on Android suddenly. It used to work earlier
We are also getting this error. It seems like there is a race condition when you call initialize and then try to call a OneSignal method.
For further context: This is happening on Android in particular - maybe related to: https://github.com/OneSignal/react-native-onesignal/issues/1554.
We are getting an error on the addTag method. This can be resolved by adding a setInterval ar
On my case the error comes because the constant of onesignalAppId is undefined when i use with Constants.expoConfig.extra.oneSignal App Id,
Im solved using process.env OneSignal.initialize( Constants.expoConfig.extra.oneSignalAppId || process.env.EXPO_PUBLIC_ONESIGNAL_APP_ID )
@tonyjimena I am not able to reproduce that issue. Were you able to get around it? Are you sure the app id was defined in the config properly?
closing for inactivity. If this is still an issue please tag and I can reopen
What happened?
I have installed in an Expo app with SDK49.0.9 and custom expo 'dev-client'. Installed
react-native-onesignal
withonesignal-expo-plugin
. I only call in 'App.tsx'OneSignal.initialize('XXXX')
And I get an error
could not invoke OneSignal.addPermissionObserver
on start up.Steps to reproduce?
What did you expect to happen?
I expected the app to run and not crash on start up.
React Native OneSignal SDK version
5.0.0
Which platform(s) are affected?
Relevant log output
Code of Conduct