开发者

Is there any shared state between iPhone apps and mobile safari?

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?


Look 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 coming 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜