Reputation: 109
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
Upvotes: 0
Views: 410
Reputation: 109
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
Upvotes: 0
Reputation: 1627
You probably have to go to Targets->Capabilities and enable keychain sharing (it enables access to keychain for your app), according to this answer.
Upvotes: 1