I\'m new with iOS development. I have to integrate Facebook login in my iOS app, as user logs in it fetches all the info and navigates it to home screen. I have done this via Fa
Swift 3 Version of solution @reena
@IBAction func loginButtonPressed(_ sender: UIButton) {
var facebookAccount: ACAccount?
let options:[String : Any] = [ACFacebookAppIdKey: "YOUR_FACEBOOK_API_KEY", ACFacebookPermissionsKey: ["email"],ACFacebookAudienceKey:ACFacebookAudienceFriends]
let accountStore = ACAccountStore()
let facebookAccountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierFacebook)
accountStore.requestAccessToAccounts(with: facebookAccountType, options: options) { (granted:Bool, error:Error?) in
if granted{
let accounts = accountStore.accounts(with: facebookAccountType)
facebookAccount = accounts?.last as? ACAccount
let dict:NSDictionary = facebookAccount!.dictionaryWithValues(forKeys: ["properties"]) as NSDictionary
let properties:NSDictionary = dict["properties"] as! NSDictionary
print("facebook Response is-->:%@",properties)
}
else {
if let err = error as? NSError, err.code == Int(ACErrorAccountNotFound.rawValue) {
DispatchQueue.main.async {
self.displayAlert("There is no Facebook accounts configured. you can add or created a Facebook account in your settings.")
}
} else {
DispatchQueue.main.async {
self.displayAlert("Permission not granted For Your Application")
}
}
}
}
}