0

I have been integrating FacebookSDK with stack overflow and some tutorial, however it's not working properly for me. I cannot fetch profile data. This method is not even called. Only "complete login" appears. Login process is working but the log out option never appears on the button as it should be. I am thankful for any tips.

 import Foundation
 import UIKit
 import FBSDKLoginKit
 import FBSDKCoreKit



 class mainView: UIViewController, FBSDKLoginButtonDelegate {

@IBOutlet weak var navigationBar: UINavigationBar!
@IBOutlet weak var mainImage: UIImageView!
@IBOutlet weak var getRecipeBtn: UIButton!
@IBOutlet weak var addImageBtn: UIButton!

let loginButton: FBSDKLoginButton = {
    let button = FBSDKLoginButton()
    button.readPermissions = ["email"]
    return button
}()

override func viewDidLoad() {
     super.viewDidLoad()

    view.addSubview(loginButton)
    loginButton.center = view.center
    loginButton.delegate = self

    if let token = FBSDKAccessToken.current() {
        fetchProfile()
    }
}

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
    print("completed login")
}

func loginButtonWillLogin(_ loginButton: FBSDKLoginButton!) -> Bool {
    return true
}

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {

}


func fetchProfile() {
    print("fetch profile")

    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, id"]).start(completionHandler:  { (connection, result, error) in guard

        let result = result as? NSDictionary,
        let email = result["email"] as? String,
        let user_name = result["fist_name"] as? String,
        let user_id = result["id"] as? String

            else {
                return
        }
        print(email)


       })
   }
}

Here is my part of console log:(I have added fbauth to info.plist.)

RecipeMaster[19428:630625] -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)" completed login

2017-02-08 22:48:23.308043 RecipeMaster[19428:640928] PAC Fetch failed with error [NSURLErrorDomain:-1003]

2017-02-08 22:48:23.308482 RecipeMaster[19428:641029] [] nw_proxy_resolver_create_parsed_array PAC evaluation error: NSURLErrorDomain: -1003

Vuko
  • 109
  • 4
  • 14
  • Possible duplicate of [How to use Facebook iOS SDK on iOS 10](http://stackoverflow.com/questions/38689631/how-to-use-facebook-ios-sdk-on-ios-10) – i6x86 Feb 08 '17 at 22:56
  • Actually, Turning on Keychain Sharing in Target's Capabilities does not work for me. Still the same problem. – Vuko Feb 09 '17 at 19:18

2 Answers2

1

You probably have to go to Targets->Capabilities and enable keychain sharing (it enables access to keychain for your app), according to this answer.

Community
  • 1
  • 1
i6x86
  • 1,557
  • 6
  • 23
  • 42
  • Actually, turning on Keychain Sharing in Target's Capabilities does not work for me. Still the same problem. – Vuko Feb 09 '17 at 19:18
  • 1
    did you put func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) return true } on app.delegate – i6x86 Feb 09 '17 at 19:38
  • Yes, posted an answer now. Still, I can't print profile info. – Vuko Feb 09 '17 at 19:43
0

I have repaired the first error -canOpenURL: failed for URL: "fbauth2:/ with setting different method in my AppDelegate (with the answer for 3.0 implementation) -> Facebook SDK sign in with Swift 3 iOS 10

Community
  • 1
  • 1
Vuko
  • 109
  • 4
  • 14
  • I cannot fetch and print my profile info thought. This error [NSURLErrorDomain:-1003] still appears. – Vuko Feb 09 '17 at 19:42