Sunday 15 May 2011

ios - Trying to return a string from a response object inside a completion handler -



ios - Trying to return a string from a response object inside a completion handler -

this question has reply here:

return value function within block 3 answers + (nsstring *) simpleauth { [simpleauth authorize:@"instagram" completion:^(nsdictionary *responseobject, nserror *error) { nslog(@"plump: %@", responseobject); nsstring *accesstoken = responseobject[@"credentials"][@"token"]; }]; homecoming accesstoken

}

trying instagram accesstoken string can utilize download info in swift viewcontroller file. had write simple auth in objective c since doesn't work swift atm.

since method run asynchronously, cant homecoming access token that. suggest add together completion block in simpleauth: method passses access token callee when gets accesstoken.

something improve approach,

+ (void)simpleauth:(void(^)(nsstring*))completionhandler { [simpleauth authorize:@"instagram" completion:^(nsdictionary *responseobject, nserror *error) { nsstring *accesstoken = responseobject[@"credentials"][@"token"]; completionhandler(accesstoken) }]; }

that way phone call this,

[someclass simpleauth:^(nsstring *accesstoken){ nslog(@"received access token: %@", accesstoken); }];

ios objective-c methods instagram completionhandler

No comments:

Post a Comment