Search code examples
javascriptiosnotificationsprogressive-web-apps

Natively installed iOS PWA application notifications


Started testing notification capabilities on iOS natively installed PWA application.

I have enabled in apple's developer account "Push notifications" checkbox on my built PWA app and requested permission to enable notifications from JS, see image below. I've been looking for ideas and testing many different aproaches, which are basically the same, but couldn't get any of them working (I mean apple notification pop-up is not appearing, like this one ios notification pop-up).

Maybe any of you solved this?

Notifications request image


Solution

  • if (
        (window as any).webkit &&
        (window as any).webkit.messageHandlers &&
        (window as any).webkit.messageHandlers['push-permission-request']
    ) {
        (window as any).iOSPushCapability = true;
    }
    if ((window as any).iOSPushCapability)
            (window as any).webkit.messageHandlers['push-permission-request'].postMessage('push-permission-request');
    

    Figured out the answer.

    Don't mind types - trial and error method