to login using facebook in iPhone sdk please use the code below.
install the pods for facebook using
- pod "FBSDKCoreKit";
- pod "FBSDKLoginKit";
- pod "FBSDKShareKit";
- pod "FBSDKMessengerShareKit"
import FBSDKLoginKit
import FBSDKCoreKit
func loginTofacebook(fbViewController:UIViewController)->Void {
let loginFb = FBSDKLoginManager();
print("loign manager value is= \(loginFb)")
let facebookReadPermissions = ["public_profile","email"]
loginFb.logInWithReadPermissions(facebookReadPermissions, fromViewController: fbViewController, handler: {(result:FBSDKLoginManagerLoginResult!, error:NSError?) -> Void in
if error != nil {
print("Error is = \(error)");
}
else
{
var allPermsGranted = true
let perms = result.grantedPermissions as NSSet
let grantedPermissions = Array(result.grantedPermissions).map( {"\($0)"} )
for permission in facebookReadPermissions {
if !grantedPermissions.contains(permission) {
allPermsGranted = false
break
}
}
if allPermsGranted {
self.fbToken = result.token.tokenString
self.fbUserID = result.token.userID
print("use descriptin is \(self.fbToken) adn other thing is = \(self.fbUserID)")
}
}
})
}
0 Comment(s)