You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have integrated one signal + next.js with one signal package I am getting notifications in chrome browser but not receiving notifications in edge browser.
this is my one signal implementation.
useEffect(() => {
router.events.on("routeChangeStart", () => NProgress.start());
router.events.on("routeChangeError", () => NProgress.done());
router.events.on("routeChangeComplete", () => NProgress.done());
const initOneSignal = async () => {
if (!isLoggedIn) {
console.log("User is not logged in, skipping OneSignal initialization.");
return;
}
//debugger;
const oneSignalExternalId = await fetchCustomerProfile();
if (typeof window !== "undefined" && isLoggedIn && !isOneSignalInitialized.current && oneSignalExternalId && router.pathname != "/") {
isOneSignalInitialized.current = true;
console.log("Initializing OneSignal...");
await OneSignal.init({
appId: ONESIGNAL_APP_ID,
// safari_web_id: ONESIGNAL_SAFARI_WEB_ID,
//serviceWorkerPath: '/OneSignalSDKWorker.js',
//serviceWorkerParam: {scope:"/"},
notifyButton: {
enable: true,
},
});
console.log("OneSignal initialized.");
// console.log('OneSignal.setExternalUserId(oneSignalExternalId) ',OneSignal.setExternalUserId(oneSignalExternalId));
// Ensure OneSignal is available before calling login
if (OneSignal && typeof OneSignal.login === 'function') {
await OneSignal.login(oneSignalExternalId);
console.log(`User logged into OneSignal with external ID: ${oneSignalExternalId}`);
} else {
console.error("OneSignal.login is not a function");
}
const notifications = OneSignal.Notifications;
if (notifications.isPushSupported()) {
console.log("Push notifications are supported.");
// Check if the user has already subscribed to notifications
const pushSubscription = OneSignal.User.PushSubscription;
console.log('User subscription: ', pushSubscription.optedIn);
if (pushSubscription.optedIn) {
console.log("User is already subscribed.");
setIsSubscribed(true);
} else {
console.log("User is not subscribed. Showing popup.");
setShowPopup(true);
}
// Add event listener to handle subscription change
pushSubscription.addEventListener("change", (change) => {
console.log("Subscription status changed:", change.current.optedIn);
if (change.current.optedIn) {
setIsSubscribed(true);
setShowPopup(false);
} else {
setIsSubscribed(false);
}
});
} else {
console.log("Push notifications are not supported in this browser.");
}
}
};
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/OneSignalSDKWorker.js?v=2')
.then(registration => {
console.log('Service Worker registered with scope:', registration.scope);
if (registration.waiting) {
registration.waiting.postMessage('skipWaiting');
}
navigator.serviceWorker.addEventListener('controllerchange', () => {
console.log('New service worker activated');
});
})
.catch(error => {
console.error('Service Worker registration failed:', error);
});
}
initOneSignal();
return () => {
console.log("OneSignal cleanup");
initOneSignal();
}
}, [isLoggedIn, router.pathname]);
The text was updated successfully, but these errors were encountered:
How can we help?
I have integrated one signal + next.js with one signal package I am getting notifications in chrome browser but not receiving notifications in edge browser.
this is my one signal implementation.
useEffect(() => {
router.events.on("routeChangeStart", () => NProgress.start());
router.events.on("routeChangeError", () => NProgress.done());
router.events.on("routeChangeComplete", () => NProgress.done());
}, [isLoggedIn, router.pathname]);
The text was updated successfully, but these errors were encountered: