Marcel
Marcel

Reputation: 683

Facebook iOS Swift SDK: Not getting callback

I'm using the facebook getting started guide to create a simple facebook login. (https://developers.facebook.com/docs/swift/login)

Whenever I tap the button it opens the facebook login view, lets me log in but afterwards doesn't fire a callback. The view just stays open and white.

let loginButton = LoginButton(readPermissions: [ .publicProfile ])
loginButton.center = view.center

view.addSubview(loginButton)

enter image description here

All I'm getting in the console is the following, if that's of any help:

2016-09-27 01:14:41.294 app[48118:6370539] -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

Upvotes: 0

Views: 802

Answers (2)

Marcel
Marcel

Reputation: 683

Turns out I was missing the AppDelegate part to handle url opens:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  return SDKApplicationDelegate.shared.application(application,
                                                   open: url,
                                                   sourceApplication: sourceApplication,
                                                   annotation: annotation)
}

Upvotes: 1

Neelam Pursnani
Neelam Pursnani

Reputation: 246

You have to allow Key-Chain sharing for iOS10: https://stackoverflow.com/a/39568942/3463712

and you have to add below code in your info.plist file

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

enter image description here

and also

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
<!--You need only fbauth2, other parameters are reference for more functionality of Facebook-->

enter image description here

Do this and let me know if your problem solves. Thanks.

EDIT: May be problem is in your loginbutton.

below code is working fine for me.

let loginbtn = FBSDKLoginButton()
loginbtn.center = view.center
loginbtn.readPermissions = ["public_profile"];
self.view.addSubview(loginbtn)

Upvotes: 0

Related Questions