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

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 {

Related

deeplinking not showing correct storyboard

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.

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.

Check if user is logged in to facebook and change viewcontroller

i have been trying the app to check if the user is already logged in or not to Facebook but i need to change the ViewController depending if the user is logged or not, here is what i got, im really confused:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window!.rootViewController = LoginViewController()
self.window!.makeKeyAndVisible()
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL?, sourceApplication: sourceApplication, annotation: annotation)
}
but, im getting an error message that says Use of unresolved identifier 'LoginViewController'
im really confused and i don't know if im near to achieve what i want.
Thanks.
P.D: this code is in the AppDelegate.swift file
This is not remotely related to Facebook or Firebase as your tag and title says.
LoginViewController class cannot be resolved in your projects scope. This is either your LoginViewController class is not available in your target. Or the actual file is not inside of your project.
Check this :
'Use of Unresolved Identifier' in Swift

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
}

Facebook login fails (always isCancelled) after upgrading to SDK 4.1

I have upgraded Facebook SDK from 3.21.1 to 4.1 in an iOS app (already live).
I followed carefully the upgrade guide, and implemented the new methods for login. The code I used is the one provided in Facebook documentation.
But since the upgrade, each time I try to log in (device or simulator, webview or Facebook app), I can go through the login flow successfully, but when I fall back on my app, the login does not return any error but returns a FBSDKLoginManagerLoginResult "isCancelled".
As a workaround, I tried to implement app invites, which do not require login, but I'm stuck with a "Attempting to authenticate in FB" in the console... No luck here either.
So I guess it has something to do with the authentication fallback and the URL scheme in the info.plist, but I double checked there, and the data (which was working fine before the upgrade) is the same as the one indicated in Facebook documentation.
Anyone has any clue??
Thanks!
What I already checked:
I did not change the info.plist which was already set up to use Facebook SDK and worked fine before the upgrade.
The user account I use for login also worked fine before this upgrade.
I do not have any currentAccessToken before or after Login process.
Thanks to Dheeraj and its answer to a similar question, I found the error in my calls. I just made the stupidest error in Swift. In the unlikely event someone as dumb as I am read this, here are the 3 calls in Swift that you should add in your AppDelegate.swift. They are tested and working:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Do what you have to do but at the end, instead of 'return true', put :
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
I found the solution, the problem is that you don't complete the Facebook login process.
when you make facebook login request and then the user uses login via facebook app, The Facebook app opens again your application and call to
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool
on app delegate, to complete the process you need to pass facebook SDK the URL that came from Facebook that way:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options) == true {
}
Then you will see that the login request will return access token and won't be canceled.
Thumbs up for your help winterized. And thanks Dheeraj bhai.
Here I'm just updating the answer for Swift 3.1.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
And yes don't forgot to put:
import FBSDKCoreKit
in App Delegate.
Another reason for the call to FBSDKLoginManagerLoginResult to always return isCancelled: if the app (in development) is asking for certain permissions, the user is not a listed developer for this app, and FaceBook has not yet approved the app for these permissions, it will always return isCancelled.

Resources