deeplinking not showing correct storyboard - ios

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.

Related

Open url from Firebase In-App-Messaging inside app

I'm trying to override Firebase's default behavior for opening the link from the In-App-Messaging following this guide:
https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=ios
I set the delegate of InAppMessaging in AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppMessaging.inAppMessaging().delegate = self
}
I add my logic in the Delegate method:
extension AppDelegate: InAppMessagingDisplayDelegate {
func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, with action: InAppMessagingAction) {
let topMostViewController = UIApplication.shared.topMostViewController()
//openUrl has logic for opening the url inside the app in a full screen webview FullScreenWKWebView, this works great
openUrl(action.actionURL, parent: topMostViewController)
}
When tapping the button in the InAppMessaging message the delegate method messageClicked is loaded perfectly and also the logic for opening the url inside the app works. BUT also the default logic from Firebase for opening the link continues so the url is opening inside the app and at the same time Firebase jumps out of the app and open the url in Safari.
Is there some way I can cancel the default logic from Firebase so that it only opens inside the app?
For HTTP links, you can intercept URL opening in the handoff:
// UIApplicationDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// handle userActivity.webpageURL
// true, if handled
return true
}

Google Sign In shows 500 error on iOS

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.

application:openURL:options: not called after opening universal link

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
}

Open application:url:sourceApplication:annotation: at launch iOS app

I want to launch or open an specific screen of my iOS app when is launching, for example using DeepLink when I click on the link in mail, if the app is running all goes OK and my app go to my desire screen, but when I try to click when app is not running goes to starting screen after launch screen.
I would like to open an specific screen with deep link but when app is not running.
Thanks
To solve this problem is necessary use
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {}
With launchOptions of this way:
if let url = launchOptions?[UIApplicationLaunchOptionsURLKey] as? NSURL { }
With it we can extract the URL and make the same as:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

Launch inactive app with URL scheme

I was able to add capability to launch my iOS app from URL (i.e.: myapp://xxxx) if the app is already running. However, if I close the app (crash it) and click on the URL, it only opens the app in the rootView instead of calling the func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool method. Any ideas? In addition, it seems the only way I can test it is on an actual device and close the app, hence I can't use Xcode to debug.
You should use "application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool" function to get url which called to open app, so modify application delegate to become like this:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//any thing need to initialise app
if let url = launchOptions?[UIApplicationLaunchOptionsURLKey] as? NSURL {
let sourceApp = launchOptions?[UIApplicationLaunchOptionsSourceApplicationKey] as? String
let annotation = launchOptions?[UIApplicationLaunchOptionsAnnotationKey] as? AnyObject
self.application(application, openURL: url, sourceApplication: sourceApp, annotation: annotation)
}
return true
}

Resources