admin管理员组文章数量:1389754
I have a website and a native iphone app. The app registers a custom protocol. I'd like the site to automatically redirect to the protocol when appropriate, but only if the user has the app installed (to avoid an annoying dialog). That means I need to write some state from the app that I can read in mobile safari to mark the app as installed. Cookies don't seem to exist cross-process. Is there anywhere else I can store my marker?
I have a website and a native iphone app. The app registers a custom protocol. I'd like the site to automatically redirect to the protocol when appropriate, but only if the user has the app installed (to avoid an annoying dialog). That means I need to write some state from the app that I can read in mobile safari to mark the app as installed. Cookies don't seem to exist cross-process. Is there anywhere else I can store my marker?
Share Improve this question asked Jun 30, 2010 at 18:25 bobpoekertbobpoekert 1,0141 gold badge12 silver badges28 bronze badges2 Answers
Reset to default 4Look at this blog post to see how Apple does it for the Mobile Me Gallery app. It involves the app opening a website (on your server) in Safari that loads an 'App Installed' cookie into Safari.
After ing back to this question I found another partial solution. It turns out that the invalid protocol dialog doesn't block javascript execution like an alert would.
So, here's how you handle fallback when launching the app from the web:
- Register a setTimeout handler to redirect to the fallback page (with window.location.replace) after, say, 500ms
- Register an onBlur handler that cancels the timeout
- Open a url with your custom protocol
- If the app is installed, the browser will open the app, blurring the page and canceling the fallback
- If the app is not installed, the user will only see the dialog for at most 500ms before they're whisked away to the fallback page
I actually like this better because while on the one hand people without the app will sometimes get a flash of dialog on the site, on the other hand it doesn't affect the first-launch experience of the app. The technique described in huntaub's answer causes a pair of distracting transitions and a flash of mobile safari on first launch of the app.
本文标签: javascriptIs there any shared state between iPhone apps and mobile safariStack Overflow
版权声明:本文标题:javascript - Is there any shared state between iPhone apps and mobile safari? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744741795a2622652.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论