I've set up universal links with the Branch SDK. The links are opening the app correctly, and application:continueUserActivity:restorationHandler: is called, but not `application:openURL:options:'
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
Branch.getInstance().application(app, open: url, options: options)
return true
}
The deprecated application:openURL:sourceApplications:annotation is also not called. didFinishLaunchingWithOptions and willFinishLaunchingWithOptions both return true.
What could possibly causing openURL to not be called when the app opens from tapping a universal link?
Clay from Branch here.
The application:openURL:sourceApplications:annotation function (now deprecate to application(_:open:options:)) is actually only called in response to the old Apple Linking system of standard URI schemes.
Universal links are actually handled within the application(_:continue:restorationHandler:) function.
// Respond to URI scheme links
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().application(app, open: url, options: options)
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
return true
}
// Respond to Universal Links
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().continue(userActivity)
return true
}
Your deep link handling should mostly be dealt with in your handler callback:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let branch: Branch = Branch.getInstance()
branch?.initSession(launchOptions: launchOptions, deepLinkHandler: { params, error in
if error == nil {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
print("params: %#", params.description)
}
})
return true
}
Related
I have an IOS App that requires a member login. I've set up a separate page for new members to log in. When I email them to confirm their new account, I want the link in the email to go to the login page in the app, which is "newlogin.php'. While testing this with Safari on my iPhone and iPad, I have tried almost everything to get this to work, but the link keeps going to the home page in the app, which is mydomain.com.
In the Associated Domains section of Xcode, I entered: applinks:mydomain.com.
Here is my apple-app-site-association file, which is in both the root directory and the .well-known directory:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "TEAMID.com.-mydomain.MyDomain",
"paths": ["/newlogin.php"]
}
]
}
}
And here is the function for the AppDelagate file that I have been struggling with for several days:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
{
// ?????????????????????????????????
}
At this point, I have no clue what to put in the function where the question marks (???) are entered, in order to make this go to domain.com/newlogin.php. Please, someone help me. I've been at this for several days, and it's starting to get to me. Thank you very much in advance.
First you will check what is the activity type where you will know you are coming from web or not.
Then get url from where you come and do necessary actions based on url.
Check below code.
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?
) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print("The url : " ,url)
// now do what you want with url
check if url contains .login.php, take user to login page in your app.
}
return false
}
Assuming you're not using SceneDelegate's, You need to register both delegate functions in your AppDelegate.swift file.:
// MARK: - URL
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard let incomingURL = userActivity.webpageURL else { return false }
// Do something with `incomingURL`
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// Do something with `url`
return true
}
I using Universal linking in my application.
When the user pick on link directly move into root view controller.
But I want to change the rootviewcontroller when user entering through Universal link.
please help to those delegates methods.
There is 2 delegate method that will fire when application is open from link or user tap link as per below.
Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// handler for URL Scheme "This will called for URL schema"
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// handler for Universal Links "This will called for Universal Link"
return true
}
Use this delegate method:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool
I have an app where I want to perform some deeplinking in.
When the app is open in the background the app opens on the correct page like expected.
But when the app is closed and then opened from the link it goes to the launchStoryboard then to the main interface storyboard and then to the storyboard I want.
But in the main interface storyboard I'm calling the api and when this is finished my app goes back to the main interface storyboard but it should stay on the storyboard like it is when the app opens from the background
Any ideas on how to takle this issue?
I followed those urls to make this happen
https://www.raywenderlich.com/6080-universal-links-make-the-connection
https://medium.com/#abhimuralidharan/universal-links-in-ios-79c4ee038272
https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
I would check for different way you handle the url when handling it on
optional public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
vs
optional public func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
optional public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
About:
optional public func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
From the documentation:
Summary
Asks the delegate to open a resource specified by a URL, and provides
a dictionary of launch options. Declaration
optional func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
Discussion
This method is not called if your implementations return false from
both the application(:willFinishLaunchingWithOptions:) and
application(:didFinishLaunchingWithOptions:) methods. (If only one of
the two methods is implemented, its return value determines whether
this method is called.) If your app implements the
applicationDidFinishLaunching(:) method instead of
application(:didFinishLaunchingWithOptions:), this method is called
to open the specified URL after the app has been initialized. If a URL
arrives while your app is suspended or running in the background, the
system moves your app to the foreground prior to calling this method.
There is no equivalent notification for this delegation method.
I followed the official guide, and checked clientID is setup correctly and URL scheme is registered.
Here is my code:
ApplicationDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Setup Google SingIn
GIDSignIn.sharedInstance().clientID = "363974216099-mnrmo2bhkg9lttb6j891g1qvdqlccr4v.apps.googleusercontent.com"
GIDSignIn.sharedInstance().scopes =
["https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/plus.me"]
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
The delegates are set in ViewController and they are not even executed.
The url scheme is registered, here is .plist:
I tried on both: simulator and device. And I always get this:
If I call signInSilently, the delegate method is called with error:
The operation couldn’t be completed. (com.google.GIDSignIn error -4.)
I made it work. You need to setup OAuth Consent screen in Credentials section. You need to select email address.
Pod
Using FBSDKCoreKit (4.23.0)
Using FBSDKLoginKit (4.23.0)
I simply cannot go pass through this function because i cannot cast URL to URL!. I did try to cast is with ! but it wont let me through. Did i miss something during the proses ?
Cheers
PS: i did create a github issues for this but it seems they did not check their github repo periodically.
In swift 3.0, the method signature for openURL is:
open url: URL
Check this post here.
In swift 3.0 use this method to open a Resource idetified by a url :
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
<#code#>
}
You are likely using the wrong method.
It's pretty standard stuff for using FBSDK. You should use
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {}
to return
application(app, open: url, sourceApplication: sourceApplication, annotation: nil)
Typically the function should look like below in your AppDelegate-
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication: String? = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: sourceApplication, annotation: nil)
}
Also, assuming that you have this, in your didFinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
Also, you should be using the Facebook Swift pods-
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
See this for more info.
I've encountered the same problem until I figured out that the URL class used in the application method
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
was pointing to an utility class defined by me. I had to rename my URL class to APP_URL and the problem disappeared.
Ruined 2 hours of my life.