So I am following the steps on the parse website ( https://www.parse.com/docs/ios_guide#fbusers/iOS ) to add Facebook login. However Xcode is giving me the error '() -> FBSDKApplicationDelegate!' does not have a member named "application' for the following line of code in my app delegate file
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
What am I missing?
It looks like you are missing the parentheses for sharedInstance.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
Related
So I've already integrated Google Sign in into my app and have the following function in my AppDelegate.swift:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// handled to go back to application after google log in
let handled = GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
return handled
}
Now I'm trying to add Facebook login and I'm supposed to add the following to that same function:
let handled = FBSDKApplicationDelegate.sharedInstance().handle(application(app, open: url, options: [UIApplicationOpenURLOptionsKey.sourceApplication], annotations: options[:])
How can I deal with having two different handled variables that need to be returned?
That's the way I found to manage both situations
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let canHandleURL = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
let canHandleGoogleUrl = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation)
if canHandleURL {
return true
} else if canHandleGoogleUrl {
return true
} else {
return false
}
}
Following #JAL suggestion, you can optimize this code adding the following lines:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) || GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation)
}
I have two custom sign in Buttons for Google and Facebook on the screen. Here is my code written in AppDelegate which causes the problem which I will explain after the code
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
return true
}
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
if #available(iOS 9.0, *) {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
} else {
// Fallback on earlier versions
}
return true
}
If I write this code then after clicking the OK button here:
The screen doesn't close up and stays there. But the Google screen works perfectly if we click the "Allow" button. But If I use this code only:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
return true
}
And remove other function then the Facebook "OK" button works fine. Why doesn't Facebook work when I add this function?
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
if #available(iOS 9.0, *) {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
} else {
// Fallback on earlier versions
}
return true
}
This solution works for me
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: nil) ||
GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String)
}
iOS Facebook and Google login at the same time?
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
// Please test this condition first, if it's works put (or) condition int return statement for GIDSignIn flag values
This below func in Swift 3.0 works for iOS 8.0 and above.
// Fallback on earlier versions
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return (FBSDKApplicationDelegate.sharedInstance().application( application,openURL: url,sourceApplication: sourceApplication,annotation: annotation) || GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation))
}
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.
I am Trying to make an app using a old tutorial. so many things have changed since the tutorial was published. I need to make an facebook login, so going through some posts i learned, FBAppCalls have changed to FBSDKApplicationDelegate, but there was a call like this in the old tutorial
FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication, withSession:PFFacebookUtils.session())
So what will it be in the new Updates of swift/xcode/fb framworks etc.?
Here is the method you can use
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(
application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
for iOS 9 this method gets called & you should use like this
func application(application: UIApplication,
openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey]! as! String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}