-
Notifications
You must be signed in to change notification settings - Fork 375
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]: fallbackToSettings YES not working good in 5.0.0 #1572
Comments
Hi @arnaudambro, thanks for reporting. I will try to reproduce this but have some questions for you:
|
hi @nan-li
import { Linking } from 'react-native';
import { LogLevel, OneSignal } from 'react-native-onesignal';
class OneSignalService {
isInit = false;
async init() {
try {
/* O N E S I G N A L S E T U P */
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
OneSignal.setConsentRequired(false);
this.isInit = true;
/* O N E S I G N A L S T A T U S E S */
this.getOneSignalPushInfos('init');
/* O N E S I G N A L H A N D L E R S */
// Add an observer
OneSignal.Notifications.addEventListener('click', this.handleNotification);
OneSignal.InAppMessages.addEventListener('click', this.handleInApp);
this.triggerEvent('ONE_SIGNAL_INIT_DONE');
return true;
} catch (e) {
console.log(e, { extra: { message: 'error init onesignal' } });
}
return false;
}
clean() {
OneSignal.Notifications.removeEventListener('click', this.handleNotification);
OneSignal.InAppMessages.removeEventListener('click', this.handleInApp);
}
handleInApp = (notification) => {
if (notification?.click_url) Linking.openURL(notification?.click_url);
};
handleNotification = (notification) => {
if (notification?.notification?.additionalData?.RedirectUrl) {
Linking.openURL(notification?.notification?.additionalData?.RedirectUrl);
}
};
listenToNotificationOnUseEffect = (listener) => {
OneSignal.Notifications.addEventListener('click', listener);
return () => {
OneSignal.Notifications.removeEventListener('click', listener);
};
};
checkNotificationPermission = async () => {
const canAsk = await OneSignal.Notifications.canRequestPermission();
const granted = OneSignal.Notifications.hasPermission();
// BE CAREFUL: https://documentation.onesignal.com/docs/ios-provisional-push-notifications
// As of 2023-09-18, `Enable iOS 12 direct to history` setting in OneSignal is enabled
// It means, by default, when installing the app the first time, `granted === true` and `canAsk === true`
// SO `granted === true` is not enough to know if the user has accepted notifications
if (typeof granted?.permission == 'boolean') {
return { canAsk, granted: granted?.permission };
}
return { canAsk, granted };
};
promptForNotificationsPermission = async () => {
OneSignal.User.pushSubscription.optIn(); // not working, lol
// if true, it should ask to open the settings if the user has already refused
// but actually there is a bug: it asks to open the settings even if the user has already accepted
// TODO: fix this bug when the lib is fixed -> https://github.com/OneSignal/react-native-onesignal/issues/1572
// until now, fallbackToSettings is disabled on iOS thanks to patch package
await OneSignal.Notifications.requestPermission(true);
this.getOneSignalPushInfos('promptForNotificationsPermission');
};
logout = () => OneSignal.logout();
triggerEvent = (event, props) => {
try {
if (!this.isInit) return;
if (!props) {
OneSignal.InAppMessages.addTriggers({ event });
} else {
OneSignal.InAppMessages.addTriggers({ event, ...props });
}
} catch (e) {
console.log(e, { extra: { message: 'error trigger event onesignal', event, props } });
}
};
}
const OneSignalNotifications = new OneSignalService();
export default OneSignalNotifications; |
Same problem here, using version 4.4.0. This only happens on ios, i'm using iPhone 14 Pro (ios 16.2). |
fixed for me just remove the line |
Any other solution that this?
|
What happened?
In SDK 5.0.0, when I use
OneSignal.Notifications.requestPermission(true);
, there is the prompt for notificationsIf I accept, there is a new alert "your notifications are turned off, go to settings"
Steps to reproduce?
OneSignal.Notifications.requestPermission(true);
What did you expect to happen?
Not seeing this alert because I accepted the notifications
React Native OneSignal SDK version
5.0.0
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: