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
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://
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.
Related
We share the App deeplinks (Universal links) with our users over email, sometimes they get wrapped by email service providers for safety.
When user taps on these wrapped deeplinks, instead of opening the App directly it opens the url in Safari.
We have a page hosted on that url. We capture the deeplink there and try to open the App using Custom URL scheme (myurlscheme://). But if the App is not installed, we try to redirect the user to the App Store page.
It all worked okay until now, but seems like Apple made some changes in Safari in the new versions of iOS (>12.3).
What’s happening now is, if the App is installed and we open the App from Safari (from Custom URL), the App Store page opens in a split second after opening our App.
This is the Javascript code that we are using:
window.location.href = 'myurlscheme://';
setTimeout(function() {
window.location.href = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
Is anyone else experiencing this. If yes, were you able to find any solution?
Update:
If we set the timeout to 4000 (i.e. 4 seconds), then it does not redirect to the App Store after launching the App.
I am trying to load a URL in react native webview which needs credentials. Normally when we open this URL in a browser like Safari and Chrome, it give us a popup to enter the credentials. Not sure how to handle it in React-Native?
We require LinkedIn authentication for our React Native application, we couldn't find a way to work with the WebView component.
This may very well be possible, however, I will highlight what solution we came up with. These steps are for an iOS React Native app, steps will differ for Android but the concept is the same. This also does require some server configuration.
We created a URL Type. In XCode, select your project and click on the Info tab. Scroll to the bottom to see URL Types. Fill in the identifier and URL Schemes. Remember what you've set for the URL Schemes. For this example, we will use myscheme.
When the app opens, we use Linking to open up the URL in Safari.
Linking.openURL('https://foo.bar');
The User could then log in via the website, once logged in, you can redirect your User back to.
myscheme://name=Dan
The myscheme matching the URL Scheme you entered within Xcode. As long as you have your application installed and the scheme matches then your app will open.
You can add any payload of information after ://.
In your React application, you can register
componentWillMount() {
Linking.addEventListener('url', this.handleOpenURL);
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL = (event) => {
const { url } = event;
if (url.startsWith('myscheme://')) {
// do something with your data.
}
};
I am trying to implement Facebook App Links using the Mobile Hosted API. Everything goes smoothly but when I test the App Link URL the app doesn't open even if installed and the URL redirects to the App Store. The custom URL for my app is set properly as when I type the custom scheme inside Safari it does open the app. It seems that something is off but can't tell why.
Here is some data:
The url that I test in the browser is:
http://fb.me/780961121977733
This is the registered data with the Mobile Hosted API:
{
id = 780961121977733;
ios =(
{
"app_name" = GoPhrazy;
"app_store_id" = 903559056;
url = "gophrazy://playerPuzzle/leo3/1420663071896";
}
);
}
The custom url scheme is registered in the info.plist as:
gophrazy://
I thought maybe the app_name case would affect it but I tested that to all lower with no effect.
Anyone has any tips on this?
Thanks
Url scheme in the info.plist MUST be always defined without leading ://
I have to open my iOS app whenever user open a link of my app in browser. I have already used a like myApp:// but i want to open my app even when user open an http link a from browser. Just like pinterest. Pinterest opens app even if i open a regular http link like this http://www.pinterest.com/pseudoamber/ and using URL scheme as well like this pinterest://www.pinterest.com/pseudoamber/. My app is opening on myApp://www.myapp.com now i want to open my app when user open an http link like this http://www.myapp.com
Anybody please help
Here is an example using jQuery:
$(document).ready(function() {
var user_agent_header = navigator.userAgent;
if(user_agent_header.indexOf('iPhone')!=-1 || user_agent_header.indexOf('iPod')!=-1 || user_agent_header.indexOf('iPad')!=-1){
setTimeout(function() { window.location="myApp://www.myapp.com";}, 25);
}
});
Is there any way to test if an iOS can handle a custom URL scheme? I have an app that registered a custom url scheme to be able to open the app from a hyperlink in mobile safari. How ever, I'd like to tell the user they need to go to the appstore to download the app if they dont have it installed.
Is there a clever way to test a URL and catch when it fails and the reason for it to fail?
This is the best I can come up with, but it's only tested in iOS 5:
If your link in mobile safari is link text,
change it to: link text,
then at the top of the /launchapp page, put a hidden iframe with the desired URL: <iframe src="myapp://path" style="display:none"></iframe>. In the body of the page, put your message about needing to go to the appstore to download the app.
If the user has the app:
They will not see the launchapp page, they will be directed seemlessly to the app url.
If the user does not have the app:
They will get a nasty alert about 'The URL could not be loaded', click OK, then they will be looking at your 'you need to download the app' page.
Update - March 2013
Check out this comment on a related SO answer. Apparently, if your app isn't already installed, you can seamlessly redirect to your app in the App Store using an approach like this (not tested):
// setup fallback (redirect to App Store)
var start = (new Date()).valueOf();
setTimeout(function() {
var end = (new Date()).valueOf();
// prevent App Store redirect upon returning to safari from myapp
if (end - start > 1000) return;
// get a seamless redirect if you use itms://... instead of http://itunes.com/...
window.location = 'itms://my/app/URI';
}, 25);
// Attempt to load my custom url scheme
window.location = 'myapp://my/path'