OneSignal-Website-SDK icon indicating copy to clipboard operation
OneSignal-Website-SDK copied to clipboard

[Question]: Should the Launch URL setting work in iOs PWA Notifications?

Open Reizoukodesu opened this issue 2 years ago • 2 comments

How can we help?

Hi, I am integrating a simple OneSignal setup to use Android and iOs PWA Push Notifications using the custom code approach. When I send Notifications manually then the notification is shown correctly, but the launch URL parameter is being ignored on iOs, Android works correctly.

The current setup looks like this:

  • We also use a minimal Workbox Service Worker setup for a positive Offline response and integrate it in the OneSignalSDKWorker.js file:
importScripts("/sw.js?v=1");
importScripts("https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js");
  • The OneSignal.init looks like this:
    window.addEventListener("load", () => {
        if ("serviceWorker" in navigator) {
            navigator.serviceWorker
                .register("/OneSignalSDKWorker.js")
                .catch((error) => {
                    console.warn("Error registering service worker:");
                    console.warn(error);
                });
        }
    });

    // Wait for domloaded
    window.addEventListener("DOMContentLoaded", () => {
        // Check if the app runs in installed mode, or at least not in default browser mode
        if (!window.matchMedia("(display-mode: browser)").matches) {
            window.OneSignal = window.OneSignal || [];
            OneSignal.push(function () {
                OneSignal.init({
                    appId: "...",
                    safari_web_id: "...",
                    welcomeNotification: {
                        title: "Some Title",
                        message: "Some message",
                    },
                    promptOptions: {
                        slidedown: {
                            prompts: [
                                {
                                    type: "push",
                                    autoPrompt: true,
                                    text: {
                                        actionMessage: "Some Message",
                                        acceptButton: "yes",
                                        cancelButton: "no",
                                    },
                                    delay: {
                                        pageViews: 1,
                                        timeDelay: 10,
                                    },
                                },
                            ],
                        },
                    },
                });
            });
        }
    });

Is the setup wrong or is it currently not supposed to be possible to open an URL in an installed iOs PWA?

Thank you for your feedback.

Reizoukodesu avatar May 24 '23 09:05 Reizoukodesu

Would it be possible to workaround the issue with Event Listeners or something similar? The ones I've identified so far in Web SDK are marked to not work on safari. Or should the feature work but my setup is messed up, thank you for your time.

Reizoukodesu avatar Jun 01 '23 06:06 Reizoukodesu

I got around this using Event listeners for the 'notificationClicked' event from memory and it works in Safari as well as the other browsers. Have you tried this yet?

rhurlbatt avatar Jul 02 '23 02:07 rhurlbatt