Use of unresolved identifier sourceApplication Facebook SDK - ios

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)

Related

Implementation of application:openURL:sourceApplication:annotation

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 have to call this two functions depending on which social network I come from in App Delegate

I'm creating an app that uses social networks to sign in. My issue is that google calls func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) ->Bool and Facebook that calls func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool.
The thing is that having that two functions in AppDelegate, Facebook doesn't take me back to app but Google does. I think there's a conflict between these two functions.
I've tried to set a flag var but I can't set an if/else statement outside of any function.
What can I do?
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(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
Each of those third party handleURL functions returns a Bool to let you know whether that particular library actually handled the URL in question. You can combine the checks into one individual delegate method and return true if either one of them returns true. I modified your code to show you what that might look like. Notice I am calling the iOS 8 deprecated function in the newer one because I am assuming you are trying to support iOS 8 as well. If that's not the case, you can get rid of that one entirely and move its body into the iOS 9 function.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
if FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
{
return true
}
else if GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
{
return true
}
else
{
// put more logic here as you need to but for now just return false if you didn't handle the URL
return false
}
}
func application(application: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool
{
return self.application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey]!)
}
edit: As a side note, the reason why your Facebook function wasn't getting called is because on an iOS 9+ system, if it detects you have implemented the newer function, it will never call the older one. If you removed the newer one entirely, you would notice the old one would still get called (and your Facebook handling would work).

FacebookSDK not able to login, giving blank white screen after authorization.

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.

What is the new function for handleOpenURL in Xcode

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()
}

ParseUI error when working to add Facebook using swift

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)
}

Resources