最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any shared state between iPhone apps and mobile safari? - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

发布评论

评论列表(0)

  1. 暂无评论