Invoke the back-to-app button programmatically - ios

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

Related

Open application on button tapped with Bundle Identifier (Without url scheme)

I'm currently developing an app and i'm trying to add a button which would open another app installed on my phone when the button is tapped
I've tried looking for the URL scheme for the app but i can't find it. Only thing i can find is the bundle ID. So i thought maybe there's a way to use the bundle ID to open the app through private APIs in Swift? My phone is jailbroken if that helps. Below is my code
#IBAction func openAppTapped(_ sender: Any) {
UIApplication.shared.openURL(NSURL(string: "itms-apps://itunes.apple.com/us/app/apspace/id1413678891?mt=8")! as URL)
}
I managed to upon the app on the appstore upon tapping the button but i want a way to open the app directly without using url schemes but instead using the bundle id and/or private APIs. Any help would be really really appreciated!
To open another app, you are either going to have to use some kind of extension provided by that app or figure out their URL scheme and reverse engineer it.
The first thing you could try is looking at the app's Info.plist and seeing if they have defined a URLScheme for their app. If not, and they haven't implemented an extension, then I think you're SOL.
If they did define it, try using it to open their app and see what happens, they might have some code that rejects or accepts a request to open their app based on the format of the URL after their scheme. If you can't figure it out with trial and error, you could use the fact that your phone is jailbroken to decompile their app and hunt down the URL parsing logic which is likely in their AppDelegate. From there you could try and build a URL that you can use to successfully open their app every time.

Set your app to detect and open when a specific link is clicked - Xcode, Swft 4

I'm currently working on an iOS app, Swift 4, that automatically launches on click of a link to block users from accidentally navigating to that link.
How would I set this up?
For example, YouTube opens up youtube.com links.
Sorry if this is a vague question, if more info is required feel free to ask ^^
If you create a custom URL protocol like myapp://somepath (where myapp is the protocol) then you just register that custom protocol, and when the user clicks such a link it’ll automatically open your app. You can’t intercept a general purpose URL protocol like HTTP or YouTube.
(At least not without OS support. That's how YouTube and the app store are able to open HTTP links.)
I haven't done anything like this so far but it seems like you should take a look at Apple URL Scheme and Universal Links:
https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
https://coderwall.com/p/mtjaeq/ios-custom-url-scheme
https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html
https://www.raywenderlich.com/128948/universal-links-make-connection?utm_source=raywenderlich.com%20Weekly&utm_campaign=95f29cf4fc-raywenderlich_com_Weekly5_31_2016&utm_medium=email&utm_term=0_83b6edc87f-95f29cf4fc-415182745

URL Scheme iOS | Open Source Application Programmtically

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(_:)

Open iOS app from browser

What I want to do is,
We have having one product info on Website.
That product is available on store.
what we have on website is that, Product info and one button for that product.
I want to take two actions on that button.
When User opens website on iPad or iPhone on Safari (browser) and click on GetProduct button, then following two actions must be taken place.
1. If user is already having product installed on device then directly open the app in device.
2. If user is not having the app on device then link user to the app on store, so he can download from there.
I already handled second condition,
but how to handle the first condition.
If I am already having the app then how to open it on action of button click in browser.
You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl: method with your application's url scheme which will then launch your app.
Here's how you setup a custom url scheme:
Open your app's Info.plist and add a row with a key called URL Types.
Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
Add another row to Item 0 and enter URL Schemes.
Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).
You should now be able to open your app from Safari by typing myScheme:// in the address bar.
Alternatively, from your app, you can launch the other app like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"myScheme://"]];
Note that you can also send parameters to the app you're launching with the url scheme (more on that here).
With iOS9 Apple introduced a way to open installed app from Links. Here is the official link for this : Apple universal links

Browser protocol handler options for ios

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.

Resources