FBSDKAccessToken currentAccessToken is not being updated after log in
Please check your appDelegate class and implement all the required methods of FB SDK. I am attaching a screenshot for the same.
FBSDKAccessToken currentAccessToken nil after quitting app
The problem is because you are calling for FBSDKAccessToken.currentAccessToken()
before having called
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
You can check for the access token anytime after calling the above line.
EDIT: Explanation
The above line lets the Facebook SDK process the launchOptions and extract the necessary information which it will require to recognise and persist the user for the application.
In cases where the user is already logged in, this simply initialises the Facebook SDK which in turn logs in the user on the basis of persisted data.
FBSDKAccessToken currentAccessToken doesn't work
I resolved it by retrieving the token string. If the token string is nil then i'll allow user to login or else i'll navigate to home page.
Some thing like this.
NSString *tokenValue = [[FBSDKAccessToken currentAccessToken] tokenString];
if ([tokenValue length] == 0)
{
NSLog(@"Allow user to login");
}
else
{
NSLog(@"User is Already logged in");
}
Hope this helps.
Thanks.
FBSDKAccessToken.currentAccessToken() found nil every time
Do following changes in your code, It will work
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
println("User Logged In")
if ((error) != nil)
{
// Process error
}
else if result.isCancelled {
// Handle cancellations
}
else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email")
{
// Do work
self.returnUserData()
}
}
}
call this method to get user email id
func returnUserData()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters:["fields":"name,email,first_name,last_name"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
println("fetched user: \(result)")
let userName : NSString = result.valueForKey("name") as! NSString
println("User Name is: \(userName)")
let userEmail : NSString = result.valueForKey("email") as! NSString
println("User Email is: \(userEmail)")
}
})
}
please remove this method
func application(application: UIApplication,
openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey]! as! String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
change this method implementation
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject?) -> Bool {
if url.scheme == "fbxxxxx"
{
//xxxxx is your APP ID
return FBSDKApplicationDelegate.sharedInstance().application(
application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}else if url.scheme == "com.googleusercontent.apps.xxxxxx"
{
// string is reverse client ID
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
}
Facebook SDK: AccessToken.CurrentAccessToken always null, even after logging in
Thanks to the question referenced by @VijayMasiwal I was able to discover the problem. I had forgot to initialize Facebook in the App Delegate.
Here is how the FinishedLaunching method should be implemented when using Facebook:
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
Settings.AppID = kFacebookAppID;
Settings.DisplayName = kFacebookDisplayName;
// I had forgotten this line :)
return ApplicationDelegate.SharedInstance.FinishedLaunching (application, launchOptions);
}
Hope that helps.
Why is [FBSDKAccessToken currentAccessToken] is nil after login in with permissions
For anyone, browsing though this, I was using FSDKLoginButton as an instance variable in order to access it through different routines. That is why it wasn't working. You have to declare the button as google said.
Related Topics
How to Change an iOS Device Volume Programmatically
How to Register Undomanager in Swift
Game Engine Collison Bitmask... Why 0X01 etc
Swift Unsafemutablepointer<Unmanaged<Cfstring>> Allocation and Print
How to Check Text Field Input at Real Time
Change Pin Image on Mkmapview in Swift
Nspredicate Filtered by Year Moth Day
Xcode5 Simulator: Unknown Option Character 'X' In: -Xlinker
iOS Uiwebview Crash in "Webthread"
Uipageviewcontroller Gesture Is Calling Viewcontrollerafter: But Doesn't Animate
How to Show Specific Language Keyboard When User Input Values in Uitextfield in iPhone App
Uisplitviewcontroller on iPad with Storyboards