Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?

前端 未结 13 2127
灰色年华
灰色年华 2020-11-22 03:55

I\'d like to have iOS to open URLs from my domain (e.g. http://martijnthe.nl) with my app whenever the app is installed on the phone, and with Mobile Safari in case it is no

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 04:24

    I think the least intrusive way of doing this is as follows:

    1. Check if the user-agent is that of an iPhone/iPod Touch
    2. Check for an appInstalled cookie
    3. If the cookie exists and is set to true, set window.location to your-uri:// (or do the redirect server side)
    4. If the cookie doesn't exist, open a "Did you know Your Site Name has an iPhone application?" modal with a "Yep, I've already got it", "Nope, but I'd love to try it", and "Leave me alone" button.
      1. The "Yep" button sets the cookie to true and redirects to your-uri://
      2. The "Nope" button redirects to "http://itunes.com/apps/yourappname" which will open the App Store on the device
      3. The "Leave me alone" button sets the cookie to false and closes the modal

    The other option I've played with but found a little clunky was to do the following in Javascript:

    setTimeout(function() {
      window.location = "http://itunes.com/apps/yourappname";
    }, 25);
    
    // If "custom-uri://" is registered the app will launch immediately and your
    // timer won't fire. If it's not set, you'll get an ugly "Cannot Open Page"
    // dialogue prior to the App Store application launching
    window.location = "custom-uri://";
    

提交回复
热议问题