Force URL to open in a Web Clip if installed?

2019-06-25 23:47发布

问题:

Let's say I have a web app that calls out to a native app via a custom URL scheme, and after the native app has done its thing it returns to my web app by opening a callback URL.

This all works fine when my web app is running in Safari. But what happens if a user saves the web app to the home screen (creating a "Web Clip")? In that case it runs in a separate process from regular safari, and has separate cookies and cache.

So when the native app tries to return to the web app, the URL will presumably get opened by Safari, not by the Web Clip, and the session will be lost. (And not just the session -- all the page state, which in a rich Javascript-based web app can be a lot of stuff with non-trivial startup time.)

Is this assumption correct? And if so, is there any way around it? Is there some way to get iOS to try to open the URL with a web clip if installed?

回答1:

In order to have something launch via a custom url scheme on iOS, you must have an application register this information via the Info.plist built into the app.

It is not possible to have a webapp/webclip register this information system-level.

So, to answer your main question, you cannot do this.

Here is the information on implementing custom URL schemes in native applications.