I know it's possible to pass data from one app to another app on the same device using custom url schemes or protocol handlers.
Is it possible to pass data from one app to another app that isn't installed? Ideally the user would be taken to the app store for the uninstalled app, the user would download the uninstalled app, and the custom url scheme from the original app would still pass the data to the newly installed app.
Is that possible?
Is it possible to pass data from one app to another app that isn't
installed?
YES.
using the x-callback parameters, we can ask the target app to call us back on our own URLs, even handling success and error scenarios.Sort of like custom HTTP headers, these callback parameters are identified with an x- namespace:
x-error : URL to open if the requested action generates an error in the target app. This URL will be open with at least the parameters “errorCode=code&errorMessage=message. If x-error is not present, and a error occurs, it is assumed the target app will report the failure to the user and remain in the target app.
x-source : The friendly name of the source app calling the action.
x-success : If the action in the target method is intended to return a result to the source app, the x-callback parameter should be included and provide a URL to open to return to the source app. On completion of the action, the target app will open this URL, possibly with additional parameters tacked on to return a result to the source app. If x-success is not provided, it is assumed that the user will stay in the target app on successful completion of the action.
Related
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(_:)
When using the implementation test from
https://firebase.google.com/docs/app-indexing/ios/test
I always get the following error:
ERROR:Google did not find App content associated with the URL.
I made sure that universal links work (i.e. open the app instead of browser on iOS device) for the entered url (which is a https:// url).
What could be the reason for this behaviour?
I am implementing firebase dynamic links in my iOS app and I can already parse the link, redirect to AppStore etc. Now I want to distinguish the first run of the app, when user installs it from the dynamic link - I want to skip the intro and show him the content that is expected to be shown.
Is there some parameter, that I could catch in application(_:didFinishLaunchingWithOptions:) so I could say that it was launched thru the dynamic link?
The method application(_:continueUserActivity:userActivity:restorationHandler:) is called later, so the intro is already launched.
This case is difficult to test, because you have to have your app published on the AppStore.
You actually don't need to have the app published in the App Store for this to work — clicking a link, closing the App Store, and then installing an app build through Xcode (or any other beta distribution platform like TestFlight or Fabric) has exactly the same effect.
According to the Firebase docs, the method that is called for the first install is openURL (no, this makes no sense to me either). The continueUserActivity method is for Universal Links, and is only used if the app is already installed when a link is opened.
I am not aware of any way to detect when the app is opening for the first time after install from a 'deferred' link, but you could simply route directly to the shared content (skipping the intro) whenever a deep link is present. If a deep link is NOT present, show the regular intro.
Alternative Option
You could check out Branch.io (full disclosure: I'm on the Branch team). Amongst other things, Branch is a great, free drop-in replacement for Firebase Dynamic Links with a ton of additional functionality. Here is an example of all the parameters Branch returns immediately in didFinishLaunchingWithOptions:
{
"branch_view_enabled" = 0;
"browser_fingerprint_id" = "<null>";
data = "{
\"+is_first_session\":false,
\"+clicked_branch_link\":true,
\"+match_guaranteed\":true,
\"$canonical_identifier\":\"room/OrangeOak\",
\"$exp_date\":0,
\"$identity_id\":\"308073965526600507\",
\"$og_title\":\"Orange Oak\",
\"$one_time_use\":false,
\"$publicly_indexable\":1,
\"room_name\":\"Orange Oak\", // this is a custom param, of which you may have an unlimited number
\"~channel\":\"pasteboard\",
\"~creation_source\":3,
\"~feature\":\"sharing\",
\"~id\":\"319180030632948530\",
\"+click_timestamp\":1477336707,
\"~referring_link\":\"https://branchmaps.app.link/qTLPNAJ0Jx\"
}";
"device_fingerprint_id" = 308073965409112574;
"identity_id" = 308073965526600507;
link = "https://branchmaps.app.link/?%24identity_id=308073965526600507";
"session_id" = 319180164046538734;
}
You can read more about these parameters on the Branch documentation here.
Hmm... as far as I'm aware, there's not really anything you can catch in the application:(_:didFinishLaunchingWithOptions) phase that would let you know the app was being opened by a dynamic link. You're going to have to wait until the continueUserActivity call, as you mentioned.
That said, FIRDynamicLinks.dynamicLinks()?.handleUniversalLink returns a boolean value nearly instantly, so you should be able to take advantage of that to short-circuit your into animation without it being a bad user experience. The callback itself might not happen until several milliseconds later, depending on if it's a shortened dynamic link (which requires a network call) or an expanded one (which doesn't).
Hypothesis:
I have a custom URL shortener that redirects to a branch.io long URL.
That custom URL domain is registered in my app's entitlements file for Universal Links.
When a user taps a short link, the app opens and calls application:continueUserActivity:restorationHandler:...
In that method I get the redirect URL (branch) that stands behind the short link, create a new NSUserActivity based on the new link and call "continueUserActivity" method (with the new activity as a parameter) from Branch SDK.
The problem is that the callback from Branch SDK doesn't return anything connected to that link. It returns as if no URL was passed.
If I hardcode the link that comes from redirect and call Branch SDK immediately, without waiting for the redirect response, then everything works fine. I suppose it's something time related in Branch SDK.
The question is: how can I make Branch recognize the link and give me back the params I need when using the redirect scheme described above? (I want to use my own URL shortener, not the one from Branch)
In determining whether a Branch link needs to be handled or not, Branch checks to verify that the NSUserActivity is of type NSUserActivityTypeBrowsingWeb. If it is, Branch checks the .webpageURL to determine if it is a Branch link. If it is not, Branch understands that no Branch link has been clicked.
To manually pass a Branch link into the SDK after the app has been opened some other way there are two functions available: .continue and .handleDeepLink.
.continue
let activity = NSUserActivity(activityType: "NSUserActivityTypeBrowsingWeb")
activity.webpageURL = URL(string: "https://testbed-swift.app.link/77Q527xswy")
Branch.getInstance().continue(activity);
.handleDeepLink
Branch.getInstance().handleDeepLink(URL(string: "https://testbed-swift.app.link/77Q527xswy"))
If you call one of these methods, the Branch SDK will handle the Branch link passed in. If these methods are not working for you, I would check to verify that you are actually passing in a working Branch link in the code and not the shortlink that you are using to open the app.
A bit of an odd situation. We work with an outside partner, which exposes a webpage where their users can log in. This webpage takes a parameter called returnURL. This returnURL will be called upon successful login to their service and at the end of this return URL our outside partner will add a token that we can use afterwards in the application.
Because I work in iOS, as a returnURL I am giving my application's URL scheme, so that the webpage can call it when the login is done.
So, it goes like this. Their webpage:
http://www.theirwebpage.com/?param1=x¶m2=y&returnURL=myAppsName://
I show the webpage in a webview and within application:openURL:sourceApplication:annotation: I have the code for the return, where I parse the parameters passed with myAppsName://
The Problem
This whole process works fine on iOS 6, as the webview will call the URL scheme of the application, which will trigger application:openURL:sourceApplication:annotation:.
However, the application:openURL:sourceApplication:annotation: method never gets called in iOS 7. It seems more like the webview calls itself the myAppsName://{parameters} and then fails (for a further explanation, the UIWebView calls webView:didFailLoadWithError: and within its NSErrorFailingURLKey we can find the full myAppsName://extraParam1=bar&token=foo).
Is there a change that happened in iOS 7, where this type of call (from a UIWebView to the application itself) is no longer permitted?
Problem with xcode 5.0 . Download the xcode version 5.0.1 . Clean all the builds ~/Library/Developer/Xcode/DerivedData/~ . Build again.