ios - Equivalent of loginViewShowingLoggedInUser -
i trying migrate app facebook sdk 3.4 4.x. used following import
#import <fbsdkcorekit/fbsdkcorekit.h> #import <fbsdkloginkit/fbsdkloginkit.h> #import <fbsdkloginkit/fbsdkloginbutton.h>
i used have 2 methods
- (void)loginviewshowingloggedinuser:(fbloginview *)loginview - (void)loginviewfetcheduserinfo:(fbloginview *)loginview user:(id<fbgraphuser>)user
i can't find these methods in 4.x sdk.
i can see fbloginview changed fbsdkloginbuttondelegate. equivalent of above 2 methods. tried looking @ facebook ios samples not figure out.
there's method called loginbutton:didcompletewithresult:error:
defined in fbsdkloginbuttondelegate :
- (void) loginbutton:(fbsdkloginbutton *)loginbutton didcompletewithresult: (fbsdkloginmanagerloginresult *)result error: (nserror *)error;
source : facebook sdk docs
note : above delegate login button, i.e. delegate called when user performs login using login button. delegate not called every time app launched loginviewshowingloggedinuser:
used do.
you have use fbsdkloginmanager check if user aleady logged in :
fbsdkloginmanager
works directly[fbsdkaccesstoken currentaccesstoken]
, setscurrentaccesstoken
upon successful authorizations (or setsnil
in case of logout).you should check
[fbsdkaccesstoken currentaccesstoken]
before calling login* see if there cached token available (typically inviewdidload
).
as retrieving user info, new sdk not automatically fetch user info. inside login success handler, have make graph request :
nsmutabledictionary *parameters = [nsmutabledictionary dictionary]; [parameters setvalue:@"id,name,email,gender" forkey:@"fields"]; [[[fbsdkgraphrequest alloc] initwithgraphpath:@"me" parameters:parameters] startwithcompletionhandler:^(fbsdkgraphrequestconnection *connection, id result, nserror *error) { if (!error) { nsstring *userid = [[fbsdkaccesstoken currentaccesstoken] userid]; nsstring *username = [result valueforkey:@"name"]; nsstring *emailid=[result valueforkey:@"email"]; nsstring *gender=[result valueforkey:@"gender"]; nsstring *userimageurl = [nsstring stringwithformat:@"https://graph.facebook.com/%@/picture?type=large", [[fbsdkaccesstoken currentaccesstoken] userid]]; } else{ nslog(@"%@",error.localizeddescription); } }];
Comments
Post a Comment