objective c - Having trouble when fetching Facebook user's details with latest iOS FBSDK (July 7, 2015) -
i have followed custom ui fblogin button app.in loginhomeviewcontroller have fblogin button.
here code using in viewdidload
fbsdkloginbutton *loginbutton = [[fbsdkloginbutton alloc] init]; loginbutton.readpermissions = @[@"public_profile", @"email", @"user_friends"]; if ([fbsdkaccesstoken currentaccesstoken]) { [[[fbsdkgraphrequest alloc] initwithgraphpath:@"me" parameters:nil] startwithcompletionhandler: ^(fbsdkgraphrequestconnection *connection, id result, nserror *error) { if (!error) { nslog(@"fetched user:%@", result); } }]; } 1) issue when first time there no console output on safari or fb logging in want user details in view controller i.e. loginhomeviewcontroller.
2) once login done in safari or fb, when goes previous view , enter controller i.e. loginhomeviewcontroller getting user details in
nslog(@"fetched user:%@", result); i tried above code in custom log in button click i.e.
- (ibaction)facebookclcik:(id)sender { } but facing same issue.
following appdelegate methods
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions : (nsdictionary *)launchoptions { [fbsdkloginbutton class]; return [[fbsdkapplicationdelegate sharedinstance] application : application didfinishlaunchingwithoptions : launchoptions]; } - (bool)application : (uiapplication *)application openurl : (nsurl *)url sourceapplication : (nsstring *)sourceapplication annotation : (id)annotation { return [[fbsdkapplicationdelegate sharedinstance] application : application openurl : url sourceapplication : sourceapplication annotation : annotation]; } - (void)applicationdidbecomeactive : (uiapplication *)application { [fbsdkappevents activateapp]; }
hope way helps retrieve user details:
- (ibaction)facebookloginbtn:(id)sender { appdelegate = (appdelegate*)[[uiapplication sharedapplication]delegate]; appdelegate.logout= true; fbsession *session = [[fbsession alloc] initwithpermissions:@[@"publish_actions",@"email"]]; [fbsession setactivesession:session]; [session openwithbehavior:fbsessionloginbehaviorforcingwebview completionhandler:^(fbsession *session, fbsessionstate status, nserror *error) { if (fbsession.activesession.isopen) { [[fbrequest requestforme] startwithcompletionhandler: ^(fbrequestconnection *connection, nsdictionary<fbgraphuser> *user, nserror *error) { if (!error) { nslog(@"accesstoken %@",[nsstring stringwithformat:@"%@",session.accesstokendata]); nslog(@"user id %@",user.id); nslog(@"email %@",[user objectforkey:@"email"]); nslog(@"user name %@",user.first_name); appdelegate.username=[nsmutablestring stringwithformat:@"%@", user.first_name]; appdelegate.firstname =[nsmutablestring stringwithformat:@"%@", user.first_name]; appdelegate.idstr= user.id; useremailstr= [user objectforkey:@"email"]; // [self fetchguestuser]; } }]; } }]; } if navigate user safari, apple may reject app
for more refer this
Comments
Post a Comment