简体   繁体   中英

Facebook Login Swift don't works On Device (But do on IOS Simulator)

I configure in my app authentication with Facebook Login in Swift 2.

Everything works perfectly on IOS Simulator (IOS 8 and 9): User click on "Login with Facebook", then a safari page opening, then authentication continue and finally user is logged correctly:

在此处输入图片说明

But when I try on my Ipod Touch , it ALWAYS block and fail on this message ( Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can ), and my user is not logged:

在此处输入图片说明

I have tried a lot of things :

  1. Change Facebook SDK (I have tried to 4.0 Facebook SDK)
  2. Upgrade my ipod touch on IOS 8.4, next on IOS 9.
  3. Downgrade Xcode 7beta to XCode 6
  4. Remove Facebook App on Ipod Touch and Reinstall it

But still not working.. Any help would be appreciated!

Here is my code:

AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        //For Facebook Login
        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)
    }

ViewController.swift

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

    @IBOutlet weak var signInButtonFB: FBSDKLoginButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        //Configure Facebook
        signInButtonFB.readPermissions = ["public_profile", "email", "user_friends"]
        signInButtonFB.delegate = self


        //Configure Facebook SignIn
        if (FBSDKAccessToken.currentAccessToken() != nil)
        {
            print("Logged in !")

        }
        else
        {
            print("not logged")

        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: Facebook
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

        print("Début login Button")
        if ((error) == nil)
        {
            print("Login Complete")

            returnUserData()
        }
        else {
            print ("Voici l'erreur:"+error.localizedDescription)
        }
    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        print("User Logged Out")
    }

Looks like my app Facebook was still in development mode.. I forget to set "Contact Name" and allow my app to public access.

SETUP FOR FACEBOOK APP:

  1. Go to : https://developers.facebook.com/apps/
  2. My Apps -> Settings -> Basic -> Contact Email = Give email valid

  3. My Apps -> Status and Review Tab -> "Do you want to make this app and all its live features available to the general public?" = Yes

I meet the same problem. I fixed by checking the login permissions. Also check again the spelling mistakes of the permission texts. Make sure your permissions are all enabled on developer.facebook.com.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM