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

本文标签: javascriptIs there any shared state between iPhone apps and mobile safariStack Overflow