英文:
Safari on iOS16.4 creates a serviceWorker without PushManager. Why?
问题
My PWA在MacOS上的Safari(以及Chrome和Firefox)上可以使用web-push,但在iOS 16.4的Safari上,ServiceWorkerRegistration对象不包含PushManager:
ServiceWorkerRegistration: {
listeners: {updatefound: Array}
active: ServiceWorker {scriptURL: "http://localhost:9200/sw.js", state: "activated", onstatechange: null, onerror: null, postMessage: function, …}
installing: null
navigationPreload: NavigationPreloadManager {enable: function, disable: function, setHeaderValue: function, getState: function}
onupdatefound: function()
scope: "http://localhost:9200/"
updateViaCache: "imports"
waiting: null
}
我知道16.4现在应该支持web-push标准,所以我错过了什么?
我已经确认不只是xcode iPhone模拟器的问题,我在实际的iPhone上也遇到了同样的问题。因为似乎是浏览器问题,所以我不知道还能尝试什么。
英文:
My PWA has web-push working with Safari on MacOS (and Chrome and Firefox), but on Safari on iOS 16.4 the ServiceWorkerRegistration object does not contain PushManager:
ServiceWorkerRegistration: {
listeners: {updatefound: Array}
active: ServiceWorker {scriptURL: "http://localhost:9200/sw.js", state: "activated", onstatechange: null, onerror: null, postMessage: function, …}
installing: null
navigationPreload: NavigationPreloadManager {enable: function, disable: function, setHeaderValue: function, getState: function}
onupdatefound: function()
scope: "http://localhost:9200/"
updateViaCache: "imports"
waiting: null
}
I know 16.4 is supposed to support the web-push standard now, so what am I missing?
I've checked that it is not just an issue with the xcode iPhone emulator, I get the same failure on an actual iPhone. I don't know what else to try because it seems like a browser issue.
答案1
得分: 2
我明白了。我在iOS的Safari浏览器上运行了PWA,这是苹果故意不支持的(与Chrome和Firefox不同)。根据官方文档,iOS 16.4或更高版本支持的是“主屏幕Web应用程序”,也就是将PWA下载到iPhone主屏幕上并从那里打开。一旦我运行了独立的PWA,ServiceWorkerRegistration包括PushManager。
另外,web推送通知在xcode模拟器中仍然无法工作,因为目前不支持。当我尝试时,应用程序会请求权限然后停在那里。然而,一旦我在实际的iPhone上测试了相同的应用程序(并将PWA下载到主屏幕上),推送通知就完全正常工作了!
英文:
I figured it out. I was running the PWA in the Safari browser on iOS, which Apple intentionally doesn't support (which is different from Chrome and Firefox). What is supported per the official documentation is "Home Screen web apps in iOS 16.4 or later", which is to say, downloading the PWA to the iPhone home screen and opening it from there. Once I ran the standalone PWA, the ServiceWorkerRegistration included the PushManager.
Side note, web-push notifications still didn't work in the xcode simulator, because they aren't currently supported. When I tried, the app would request permissions and just be stuck there. However, once I tested the same app on an actual iPhone (and downloaded the PWA to the home screen), push notifications were fully functioning!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论