3
votes

When I click on login with Facebook button, on the IOS simultor its working fine. Getting PFUser object.Then If I run the same code on the iPhone device, getting PFUser object as null. No error.

Code:
 func loginWithFacebook()
    {
        print("login with facebook")
        let permissions = ["public_profile"]
        PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: {
            (user: PFUser?, error: NSError?) -> Void in
            print("################")
            if let error = error {
                print(error)
            } else {
                if let user = user {
                    print(user)
                }
            }

        })
    }

IDE : xcode 7 Language : Swift2 Facebook SDK : 4.6.0 Parse: 1.8.4 device: iPhone 5s I have verified .plist is having all keys which are required. Also verified the bundle identifier for typo mistakes. All look good. Facebook app is active.

Any help?

2

2 Answers

5
votes

In the AppDelegate.swift, I have the following code:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url,  sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String,
            annotation: options["UIApplicationOpenURLOptionsOpenInPlaceKey"]!)
    }

As per comments in the UIApplicationDelegate, we should use application:openURL:options:, but still it is not working.

 @available(iOS, introduced=4.2, deprecated=9.0, message="Please use application:openURL:options:")
    optional public func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool

Now I have changed to the following code:

 func application(application: UIApplication,
        openURL url: NSURL,
        sourceApplication: String?,
        annotation: AnyObject) -> Bool {
            return FBSDKApplicationDelegate.sharedInstance().application(
                application,
                openURL: url,
                sourceApplication: sourceApplication,
                annotation: annotation)
    }

Then, it started working fine on both simulator and iPhone device.

0
votes

Check out this guide to solve the issue http://discoverpioneer.com/blog/2015/09/18/updating-facebook-integration-for-ios-9/

The issue has to do with App Transport Security. A few changes to your info.plist and you'll be all set :)