iphone - facebook iOS sdk custom delegate and SSO authorization -
i've been toying new facebook ios sdk. have gotten project point can login successfully. have 2 questions:
1) hit graph api issue following call: [facebookinstance requestwithgraphpath:@"me" anddelegate:self]. possible specificy delegate other self? responses go (void)request: (fbrequest *) request didload:(id) result. since app may issue requests facebook api @ different times , need different things happen each respective request issued, how can specifiy callback function response should hit in app? possible?
2) once user has logged in, how can check authorization/login status can disable login button if logged in? consider example of user turning on app 1st time , logging in. closing app, , opening few minutes later. rather not show user login button 2nd time , instead start pulling information display such name.
1) there shouldn't wrong specifying delegate other self, long object provide delegate conforms fbrequestdelegate protocol. alternately can interrogate fbrequest object in delegate method determine request loaded , appropriate response is.
2) make user stays logged in, need save accesstoken (an nsstring) , expirationdate (an nsdate) properties of facebook object when user logs in. then, when log user in, attempt restore these values. code snippets may help:
- (void)fbdidlogin { nsstring *tokenstring = [[self facebook] accesstoken]; nsdate * expirationdate = [[self facebook] expirationdate]; [[nsuserdefaults standarduserdefaults] setobject: tokenstring forkey:@"facebooktoken"]; [[nsuserdefaults standarduserdefaults] setobject: expirationdate forkey:@"facebookexpirationdate"]; [[nsuserdefaults standarduserdefaults] synchronize]; }
and, when need log user in:
nsstring *tokenstring = [[nsuserdefaults standarduserdefaults] objectforkey:@"facebooktoken"]; nsdate *expdate = [[nsuserdefaults standarduserdefaults] objectforkey:@"facebookexpirationdate"]; if (tokenstring != nil && expdate != nil) { [facebook setaccesstoken:tokenstring]; [facebook setexpirationdate:expdate]; } if ([facebook issessionvalid]) { //your session valid, whatever want. } else { //your session invalid //(either session past expiration date or there no saved data login) //you need ask user log in }
Comments
Post a Comment