Husein Behboudi Rad
Husein Behboudi Rad

Reputation: 5462

How to define url schemes starting with http ios7

I can define custom schemes like myapp so that third applications can redirect links like: myapp://mypage.com to my app(if user installed it). but I want that third applications open my app if user try to open links like http://mysite/mypage.com too.

Right now we can see that safari open yourtube when we type links like:

http://www.youtube.com/watch?v=WZH30T99MaM

Or map application opens if we type links like:

http://maps.google.com/maps.....

So how can I define a custom scheme that third applications open my apps if user type:

http://a.myapp.com

Upvotes: 2

Views: 255

Answers (2)

teamnorge
teamnorge

Reputation: 794

Possible workaround, you register your custom URL Scheme and then in your HTML/JS code of the start page of your site you check if the the browser agent is Mobile Safari and forward it to the URL with custom scheme.

You can also check if app is not installed and redirect to AppStore, simply by opening AppStore link with the timeout, so if the redirection attempt to custom URL Scheme link fails you go to to App Store.

<script type="text/javascript">
var app = {
    isSafariMobile: function () {
       return navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/)
    },
    launchApp: function() {
       window.location.replace("myapp://");
       this.timer = setTimeout(this.openAppStore, 1000);
    },
    openAppStore: function() {
       window.location.replace("https://itunes.apple.com/app/Myapp");
    }
};

if (app.isSafariMobile()){
  app.launchApp();
}

</script>

UPDATE: The Safari detection method may be slightly adjusted, the ios chrome app could also be detected as Safari by this code as it has WebKit in its UserAgent string on iPhone.

Upvotes: 1

Duncan C
Duncan C

Reputation: 131418

Short answer: You can't without server support. Apple does tricks that are not available to third party apps to redirect HTTP URLs like Maps and Youtube.

The only way you could do this would be to set up a web server at http://a.myapp.com that redirected to myapp://

Upvotes: 2

Related Questions