I have a working universal link that works when used by another app. eg. if I write the link in notepad it will open app the app. But when I call the following inside the app that the universal link links to, it will open in safari. canOpenURL returns true.
have set up this .well-known/apple-app-site-association and also the correct intent-filter. I think its working because the links open the app when clicked outside of the app.
let url = Foundation.URL(string: "https://workingdeeplink.com/")!
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
This is expected behaviour. When an app passes its own universal link to open, iOS will open that link in Safari.
The purpose of this is to allow a fallback when an app cannot handle an incoming link. The logic for handling an incoming link is typically something like:
Parse the incoming link
Determine if the app can handle it
If it can, then handle the link (e.g. select a specific view or take some action)
If it can't, pass the link to open so that the user is redirected back to the web site, where the link can be handled.
This avoids the situation where a deep link opens your app and then nothing happens or an error is shown (because the app can't handle the url)
There shouldn't be a case where your app tries to open a deep link it can handle; it can simply bypass then whole deep link process and take the action that would result directly.
Related
I have the opposite problem of iOS open YouTube App with query (url schemes).
Basically I have a URL such as https://youtu.be/A4yitOx14Bg. When the user taps it, or when I open URL, it normally opens up in the YouTube app. The user can usually customize this behavior with a non-obvious gesture. Namely they can tap and hold the link, and then choose to “Open in YouTube” or “Open in Safari”.
Is there some form of the URL that will always force it to open in mobile Safari, and not require user intervention?
I found this site which has a bunch of different formats: https://gist.github.com/rodrigoborgesdeoliveira/987683cfbfcc8d800192da1e73adc486
Pasting it into notes reveals that the only formats that force a page to load into safari are the youtube-nocookie.com urls. This is an official URL from Google, mentioned here.
Thus the same link above can be changed to https://www.youtube-nocookie.com/embed/A4yitOx14Bg and it’ll forcibly load in mobile Safari.
I used to have a UIButton that would load an URL in the form of itms://example.com this when pressed would load the relevant item within the AppStore application on iOS (rather than in the browser).
However that is no longer working for me. If I switch the URL to https:// then the relevant page opens in the browser but if I use itms or itms-apps then it does nothing. Any ideas why or if there’s a new way of doing this?
The use case is to refer people from one app to download another from the AppStore.
Using the http link should open directly into App Store app via universal links.
// open Google Earth in the app store
UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/google-earth/id293622097?mt=8")!, options: [:], completionHandler: nil)
If you wish to keep the experience inside of your app, then use SKStoreProductViewController as pointed out by rmaddy
Scenario is user will get a link to his email. If user clicks on the link, If app is already installed, app should open and if app is not installed it should redirect to app store.
I've seen deeplinks implementation, but I believe it needs some more implementation in backend too. Can any one help on this?
Redirect to application if installed, otherwise to App Store
gone through this. Is there any better way?
added gif for one more scenario:
in the below gif, from email to app it navigates directly? how?
I'm assuming the link you want to pass by email is an https link. If that's the case, for iOS to be able to redirect it to your app, you'll need to implement universal links. This implementation requires you to register the domain you want to respond to on your entitlements file and add an apple-app-site-association file to your backend. This way Apple can verify the domain you're trying to respond to is really yours.
As a result, when the app gets installed, it can be invoked by your domain links via deeplinking.
Now when there's no installed app able to respond to a specific https domain link, the system will simply open it on a web browser. Consequently, you cannot force iOS to open such links on AppStore directly. What you can do is to check whether the running device is iOS when your website gets accessed and ask the system to show your app on AppStore.
And to request iOS to launch AppStore from a website you can use itms-apps:
const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
if (iOS) {
// Just replace `https://` with `itms://` on your app's AppStore link.
window.location.href = "itms://itunes.apple.com/us/app/google-maps-transit-food/id585027354?mt=8";
}
// In this example I'm redirecting to Google Maps app page on AppStore.
Note: This is just a simple example used to demonstrate the concept. For a real application, you may want to use a device detection library for browsers, like mobile-detect.js
My suggestion is check iOS version
here Example
let url = URL(string: "www.stackoverflow.com")!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
Any ideea how is this getting true in
appUrl = "http://dum:site2015#jobz.store.com/
if UIApplication.shared.canOpenURL(appUrl!){
if #available(iOS 10.0, *) {
UIApplication.shared.open(appUrl!)
}
and in url scheme i have jobz-com
the thing is it getting true althought I don't have the app installed ...instead is opening the url in safari... but why is not getting false since i don't have the app installed?
This function does not check for apps installed. It just tells you if it can open that URL, in safari or through an app.
A valid URL will always return true because the system can actually open it somewhere.
According to Apple's own documentation
A URL (Universal Resource Locator). At runtime, the system tests the URL’s scheme to determine if there is an installed app that is registered to handle the scheme. More than one app can be registered to handle a scheme.
https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl
Safari is registered to handle any valid URL, so if the app using the scheme does not exist, the next application registered to read it is safari.
I don't think there's an open API for you to only open an URL if the app is installed.
And always make sure that your URL starts with the scheme you need and not HTTP/S.
my-app://myurl/parameters
Do not use http:// or https:// to open apps. These are for websites. Use app url schemes like this:
jobz-com://
Edit
Another way of doing what the questioner is trying to achieve is to use Universal Link.
Here is the Apple's Official doc about Universal Links and you can follow this medium article which says:
The workaround approach to deep linking with URI schemes involves
using a traditional http:// link to launch a web browser. This link
contains a JavaScript redirect to a custom URI scheme, which is
executed by the web browser to launch the app. If the redirect attempt
fails because the app is not installed, the JavaScript then takes the
user to the App Store or Play Store.
Instead of opening up
Safari first when a link is clicked, iOS will check if a Universal
Link has been registered (an AASA (apple-app-site-association) file
should be there in the domain which contains the bundle id of the app
and the paths the app should open) for the domain associated with the
link, then check if the corresponding app is installed. If the app is
currently installed, it will be opened. If it’s not, Safari will open
and the http(s) link will load.
I have a button in my app that opens a link via safari. There are some tasks user does in web and finally returns to app on pressing a button in browser. what I need to do is to terminate app when safari opens so that when user comes back form browser, app inits without previous data.
That's how I open link:
let adrs = "mylink"
UIApplication.shared.openURL(NSURL(string: adrs) as! URL)
How can I achieve this?
Technically you can just exit the program (e.g., exit(0)). However, you should not do so, as iOS apps should not terminate on their own. Rather clean up your UI, e.g., remove all view controllers and create new ones.