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
}
Related
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.
I started working on the app before the release of Xcode8 and and then switched over , When I try to log into the app using Facebook login I get the following error
Implementation of application:openURL:sourceApplication:annotation: not found. Please add the handler into your App Delegate. Class: GhostGab.AppDelegate
I checked all the settings and they seemed fine . Any help will be appreciated
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(
application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
// Add any custom logic here.
return facebookDidHandle
}
Your function definition:
func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
}
Should be replaced by:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
}
There's an underscore for the first parameter and Any in place of AnyObject for the last parameter type.
That's why you're getting the error:
Implementation of application:openURL:sourceApplication:annotation
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 {
When user tries to auth in app using facebook, safari window doesnt disappear after user grants permissions inside it. Safari reloads page and remains blank, not dismissing and not returning user to app
My appDelegate methods are following
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
Where can be the problem ?
I was following this tutorial to implement a Facebook login. I did the exact same thing and checked twice, but get an error while compiling that he doesn't get.
In my AppDelegate.swift:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
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)
}
and I get this error for the second function: Definition conflicts with previous value, expected declaration.
I hope somebody understands the error here, thanks.