-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Could not invoke OneSignal.addPermissionObserver #1552
Comments
The API has changed in the 5.x version. Try using
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
And I get the error. I'm no Android expert, but I think the issue is somewhere there:
The 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'. |
@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? |
Hi @emawby , apologies for the late reply. and from my yan.lock I see that those versions exactly resolved. |
Gettings
|
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: #1554. Example Code for initializationconst handleIngredientChangeNotification = useCallback(() => {
presentScreen(RootScreen.Inbox);
oneSignalService.setTagToTrue('hasOpenedIngredientChangeAlert');
}, []);
const handleNotification = useCallback(
(notification: OSNotification) => {
if (notification.additionalData) {
const { type } = notification.additionalData as NotificationData;
switch (type) {
case NotificationEventType.IngredientChangeEvent:
handleIngredientChangeNotification();
}
}
},
[handleIngredientChangeNotification],
);
const didReceiveOpenNotificationHandler = useCallback(
(event: NotificationClickEvent) => {
// Handle the notification after delivery from the background
handleNotification(event.notification);
analyticsService.logPushNotificationEvent(
AnalyticsEvent.PushNotificationOpened,
{
notificationId: event.notification.notificationId,
templateId: event.notification.templateId ?? '',
type: PushNotificationEventType.IngredientChangeNotification,
},
);
},
[handleNotification],
);
const didReceiveForegroundNotification = (
event: NotificationWillDisplayEvent,
) => {
event.preventDefault();
const notification = event.getNotification();
notification.display();
analyticsService.logPushNotificationEvent(
AnalyticsEvent.PushNotificationShownInForeground,
{
notificationId: notification.notificationId,
templateId: notification.templateId ?? '',
},
);
};
useEffect(() => {
// OneSignal Init Code
oneSignalService.initialize(ONESIGNAL_APP_ID);
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
const promptForPush = async () => {
if (await OneSignal.Notifications.canRequestPermission()) {
OneSignal.Notifications.requestPermission(false);
}
};
promptForPush();
// Method for handling notifications opened
OneSignal.Notifications.addEventListener(
'click',
didReceiveOpenNotificationHandler,
);
OneSignal.Notifications.addEventListener(
'foregroundWillDisplay',
didReceiveForegroundNotification,
);
return () => {
OneSignal.Notifications.removeEventListener(
'click',
didReceiveOpenNotificationHandler,
);
OneSignal.Notifications.removeEventListener(
'foregroundWillDisplay',
didReceiveForegroundNotification,
);
};
}, [didReceiveOpenNotificationHandler]); We are getting an error on the addTag method. This can be resolved by adding a setInterval ar Example call to addTag /**
* Calls provided function when this service has been initialized
*
* @param onSafe function to call
*/
private safeCall = (onSafe: () => void, maxTries: number = 1) => {
if (this.initialized) {
onSafe();
} else if (maxTries > 0) {
console.log(`waiting on onesignal`);
let tries = 0;
const callTimer = setInterval(() => {
tries++;
if (this.initialized) {
clearInterval(callTimer);
onSafe();
} else if (tries >= maxTries) {
clearInterval(callTimer);
logError('exceeded maxTries for OneSignalService safeCall');
}
}, 500);
} else {
logError('OneSignalService not initialized');
}
}; |
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 |
@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
The text was updated successfully, but these errors were encountered: