I was using this code to FB login:
@IBAction func fbloginbtn(sender: AnyObject) {
FBSDKLoginManager().logInWithReadPermissions(["public_profile", "email","user_location","user_about_me", "user_photos", "user_website"], handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if (error == nil){
let fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("email"))
{
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
//do sth
}
})
}
}
}
})
}
But loginwithreadpermissions
is deprecated in SDK 4.6
How should I change this code?
If you look at the documentation, you'll see the mention of alternative api as well.
From the documentation of FBSDKLoginManager
, it says:
- (void)logInWithReadPermissions:(NSArray *)permissions
handler:(FBSDKLoginManagerRequestTokenHandler)handler
__attribute__((deprecated("use logInWithReadPermissions: fromViewController:handler: instead")));
So there is a new method, that takes an additional parameter of UIViewController
as well, to determine from where the login sequence was initiated. As documentation says:
- (void)logInWithReadPermissions:(NSArray *)permissions
fromViewController:(UIViewController *)fromViewController
handler:(FBSDKLoginManagerRequestTokenHandler)handler;
and the explanation for parameters says:
fromViewController
- The view controller to present from. If nil, the topmost view controller will be automatically determined as best as possible.
Since, there's only one additional parameter, you could add it to existing implementation like this:
FBSDKLoginManager().logInWithReadPermissions(["public_profile", "others"],
fromViewController:self //<=== new addition, self is the view controller where you're calling this method.
handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
})
The latest xcode should also suggest you when you write, logInWithReadPermissions
with all available options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With