1
votes

I was having issue with iOS 8.4 compilation with Facebook SDK so I upgraded to Xcode 7.1 and using Facebook Sdk 4.6. I am following the below code for the login. It's giving me weird experiences, sometimes, it opens up SafariViewController, some times it opens both popup view and SafariViewController and sometimes it opens up only pop -up view.

In Any of the case, I try to login I don't get data in neither

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)

or in

fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in if (error == nil)

I have followed and added the NSTransportExceptions too

Codes

In ViewDidload I defined this

    fblogin.delegate = self
    fblogin.readPermissions = ["public_profile", "email", "user_friends"]

fblogin is the loginButton

@IBAction  func loginFb(sender:AnyObject)
{
    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web
    fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in
        if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result
            if fbloginresult.grantedPermissions != nil { //Here we have to check that the set contains value or not
                if(fbloginresult.grantedPermissions.contains("email"))
                {
                    self.getFBUserData()
                    //fbLoginManager.logOut()
                }
            }
        }
    })
}
func getFBUserData(){
    NSLog("Called")
    if((FBSDKAccessToken.currentAccessToken()) != nil){
        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
            if (error == nil){
                self.dict = result as! NSDictionary
                print(result)

                print(FBSDKAccessToken.currentAccessToken().tokenString)
                //NSLog(self.dict.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as! String)
            }
        })
    }
}

I was having issue with Facebook is not returning data in didCompleteWithResult in iOS 9 so I upgraded to Xcode 7

1
latest Facebook sdk is 4.8 did you try upgrading? try to follow fb getting started guide again to see if you missed any step - Tomer Even
also try the parameter values without spaces e.g. "id,name,first_name,last_name,email" - Tomer Even
I tried man however its opening with SafariViewController and after I Authenticate, its not closing the safariviewcontroller, not redirecting to the app.. - Saty
Only in v4.5 it's redirecting to the app. After 4.6 it's using sfsafaricontroller. You can force using 4.5 to fix this - Tomer Even
I'm going to sum up my comments as an answer please accept it if they helped you - Tomer Even

1 Answers

1
votes

In order to make a valid fields request they need to be without spaces e.g. "id,first_name,last_name,email"

About the switching to the Facebook app instead of showing SFSafariViewController you need to use any Facebook SDK before v4.6 in which they changed this