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
Related
I'm making an app and i want integrated Facebook, but this error can't continue, attached my problem.
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
// Override point for customization after application launch.
return true
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation:annotation) } THIS IS THE PROBLEM -- > ////Use of unresolved identifier "sourceApplication"///
}
}
Your delegate method does not match the one being used by Facebook. What about something like this?
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
The following code to implement FB login into my app
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
However I keep getting two error messages both similar,
"Use of unresolved identifier 'annotation'
"Use of unresolved identifier 'sourceApplication'
I'm not exactly sure what's causing this error but I have a feeling its a bit of code that's been deprecated. Does anyone know what the current alternative is?
appdelegate.swift
I´m using this code in my app delegate and works perfect
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
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)
}
You have a variable name mismatch:
You declare your UIApplication as app in the first line, but try to reference it by sourceApplication in your return statement. Replace sourceApplication with app. Same with annotation, change that to options:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: app, annotation: options)
Added URL Type , LSApplicationQueriesSchemes and other settings.
Tried every possible solution, Not able to debug. Please help with this
I solved this by implementing BOTH of these functions, even though facebook's developer website only lists one:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let shouldOpen :Bool = FBSDKApplicationDelegate.sharedInstance().application(
app,
openURL: url,
sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String,
annotation: nil)
return shouldOpen
}
For anyone fighting this for swift3 + ios10, make sure your appdelegate looks like:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func applicationWillResignActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
source
If this is helpful for anyone - I had the Facebook login button on a detached controller (specifically within a custom view that presented a separate View Controller). Once I placed the button inside the parent view controller, things worked instantly.
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.