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
Related
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
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 ?
This is what I do in my controller:
let button = FBSDKLoginButton(frame: CGRectMake(100, 100, 300, 50))
button.readPermissions = ["public_profile", "user_friends"]
view.addSubview(button)
After viewDidLoad I click that button, write my login and password and since then I always have such view:
How to log out from that? It appears always, even I remove the app from Simulator. What is wrong?
Below two methods must be implemented in AppDelegate:
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)
}
And then once you click Log In with Facebook and then OK, your FBSDKLoginButton will change to:
Once you tap this, you are able to logout with following dialog:
1> GOTO the safari app and open facebook.com
2> Open your account preference.
3> log out form your account.
OR
1> GOTO "Setting".
2> Click "Safari".
3> Click "Clear History and Website Data".
Also you remove app Permission from facebook than go to Profile-->APP-->find your application name -->remove data.
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
}
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.