ios - How to wait and get the proper result in caller class from a block function of second class -
i having difficulty result block function second class.
the below function returns boolean value first class.
- (bool)loadaccountwithusername:(nsstring *)username password:(nsstring *)password hostname:(nsstring *)hostname oauth2token:(nsstring *)oauth2token { __block _bool bloadedsuccess = false; self.imapsession = [[mcoimapsession alloc] init]; self.imapsession.hostname = hostname; self.imapsession.port = 993; self.imapsession.username = username; self.imapsession.password = password; if (oauth2token != nil) { self.imapsession.oauth2token = oauth2token; self.imapsession.authtype = mcoauthtypexoauth2; } self.imapsession.connectiontype = mcoconnectiontypetls; masterviewcontroller * __weak weakself = self; self.imapsession.connectionlogger = ^(void * connectionid, mcoconnectionlogtype type, nsdata * data) { @synchronized(weakself) { if (type != mcoconnectionlogtypesentprivate) { } } }; // reset inbox self.messages = nil; self.totalnumberofinboxmessages = -1; self.isloading = no; self.messagepreviews = [nsmutabledictionary dictionary]; [self.tableview reloaddata]; nslog(@"checking account"); self.imapcheckop = [self.imapsession checkaccountoperation]; [self.imapcheckop start:^(nserror *error) { masterviewcontroller *strongself = weakself; nslog(@"finished checking account."); if (error == nil) { [strongself loadlastnmessages:number_of_messages_to_load]; bloadedsuccess = true; } else { nslog(@"error loading account: %@", error); } strongself.imapcheckop = nil; }]; return bloadedsuccess; } i want call function 2nd class , result.
masterviewcontroller = [[masterviewcontroller alloc] initwithnibname:nil bundle:nil]; bool loadsuccess = [masterviewcontroller loadaccountwithusername:username password:password hostname:hostname oauth2token:nil]; the issue is, getting result false in 2nd class loadsuccess, since loadaccountwithusername gets result in block function after few minutes. time, 2nd class gets returned false value instead of true
how can caller class wait , proper result block function class?
kindly advise.
Comments
Post a Comment