By browser protocol handler I mean spotifiy:// and coda://.
What options exist for iOS safari. Could I specify a BPH for dropbox or evernote and the browser would know to prompt "open item in evernote" for example?
Is this possible?
You can use -[UIApplication openURL:] to open an arbitrary URL. If another app has registered for the protocol scheme, they will then handle the URL. Similarly there's -[UIApplication canOpenURL:] to find out if a URL scheme can be handled before you attempt to invoke it. Note however, the OS does not prompt the user when you open a URL, it simply launches the app that's currently registered for that URL scheme and gives them the URL. If you want to prompt the user before this happens, you should do so yourself.
Related
Is is possible to call the "back-to-app" button programmatically? I have only seen questions for the scenraio when people want to call back-to-app from OtherApp which I understand why it shouldn't be available.
MyApp -> OtherApp : call back-to-app from OtherApp.
However in my scenario is this:
OtherApp -> MyApp : call back-to-app from MyApp.
Is it possible to send the user from MyApp back to where they were before? Because my app has completed its purpose?
If you’re talking about the button that appears at the top left when switching apps, no you can not invoke that button.
For your app to open another app you’ll need to know the URL Scheme of the app you want to open. The other app must also be setup to handle this URL Scheme.
If you own both apps you can implement the URL Scheme yourself. If not, you’ll need to reach out to the developer of the other app to see if they have a URL Scheme you can open their app with.
Apple docs: Defining a Custom URL Scheme for Your App
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 2 iOS applications, using URL Scheme I am able to open app B through A like I have created URL Scheme in B and using OpenURL calling it from application B. Also, I am able to pass the data.
But what I am looking for, is there a way to move back to application A on some specific event.
In B I am getting all details about A in sourceApplication but how to move back?
Do we need to create URL Scheme for both of the apps for communicating with each other? or is there any way to invoke sourceApplication and move back?
Issue 1
in case of Facebook SDK, I create URL Scheme for my app because once authentication is done I want Facebook SDK to call my app that right but I didn't register my app scheme in Facebook SDK info.plist. how does it work?
Issue 2
I have tried on Simulator and device both. if I call canOpenURL it gives me an error
-canOpenURL: failed for URL: "openb://" - error: "This app is not allowed to query for scheme openb"
But If I directly call UIApplication.shared.open it launches the application successfully.
Any leads here?
If you want to invoke iOS application from another iOS app URL Scheme is the way. A URL scheme lets you communicate with other apps through a protocol that you define. To communicate with an app that implements such a scheme, you must create an appropriately formatted URL and ask the system to open it. To implement support for a custom scheme, you must declare support for the scheme and handle incoming URLs that use the scheme.
How to move back or open sourceApplication?
To achieve this you have to create URL Scheme for both of the application.
Issue 1 and 2
Before iOS 8, everyone was using canOpenURL for checking whether this URL is exist for not and if yes openURL for invoking the application. But concern came when few developers/apps started using it to track the user iPhone (what all application is installed) for advertising purposes etc. That's why Apple came up with the solution called URL Scheme Whitelist.
So according to that, if you want to use canOpenURL you have to whitelist the URL Scheme otherwise it will through an error like error: This app is not allowed to query for scheme and if you want to open the application use openURL directly.
Yes it broke lots of SDKs login flow but it makes sense.
For more information, canOpenURL(_:)
I successfully have a message url from the gmail api:
https://mail.google.com/mail/?authuser=roy#companyemail.co#all/155134b5e66a9b06
However, when i call the [[UIApplication sharedApplication] openURL:url] method, the web client gets opened up instead of the native iOS application (and just shows the inbox, not the specific message). Not sure if it has to do with the LSApplicationQueriesSchemes or not, but regardless - couldn't find any documentation on this in the Gmail iOS documentation, so if anyone has any ideas!
Thanks
Through the links the Brett posted, this deep link url allowed me to open gmail:
googlegmail://
Still searching for instructions on deep linking to a specific email though
It seems that the openURL method is designed to do what you want to do. But any URL which starts with http: or https: is going to open in Safari. Here is a quote from the doco.
A URL (Universal Resource Locator). UIKit supports many common
schemes, including the http, https, tel, facetime, and mailto schemes.
You can also employ custom URL schemes associated with apps installed
on the device.
I presume that if you wanted to compose a message in the built-in Mail app, you would use a mailto: URL. Not sure about opening an existing message. And if you want to open an existing message in another app, then that app would need to define a custom URL scheme, and you'd need to use that.
I have successfully mapped my app to a custom URL Scheme, so when I type myApp://path my app opens. To do so I used Info.plist's CFBundleURLSchemes and CFBundleURLName.
I wonder if I can map a URL pattern too, instead of the scheme, so when somebody types
http://mylegitdomain.info/blah
my app opens. This is possible in Android.
There isn't a built-in way to do this - the http: and https: schemes automatically open Safari.
However, here's what you could do:
Register mylegitdomain.info
Run a server that simply redirects requests to mylegitdomain.info to myApp://path
This won't be quite as seamless to the user - the URL will open Safari and then redirect to your app - but it will work, and it might be worth it depending on your use case.