ios - UIKeyboardTaskQueue threading issue -
i'm new ios development , i've been stuck on bug while. i'm making simple app uses web service. right have 2 view controllers. login view controller (with nib file) , main view controller (with nib file). when created app chose empty application don't have storyboard. instead i'm using uinavigationcontroller
. when run code next error after entering username , password , pressing submit in login view:
terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: '-[uikeyboardtaskqueue waituntilalltasksarefinished] may called main thread.'
this code have submit button:
-(ibaction)login:(id)sender{ uiapplication *application = [uiapplication sharedapplication]; application.networkactivityindicatorvisible = yes; [_loginnetworkingcontorller checkcredentialswithusername:self.username.text withpassword:self.password.text completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { if(!error){ nshttpurlresponse *httpresp = (nshttpurlresponse*) response; if (httpresp.statuscode == 200) { nslog(@"sucess"); nsdictionary *credentials = @{self.username.text: self.password.text}; [keychainuserpass save:@"my app" data:credentials]; uiviewcontroller *mainview = [[rdmainviewcontroller alloc] initwithnibname:@"rdmainviewcontroller" bundle:nil]; [self.navigationcontroller pushviewcontroller:mainview animated:yes]; } else{ nslog(@"error"); } } else{ nslog(@"error"); } }]; }
and here code next function
[_loginnetworkingcontorller checkcredentialswithusername:self.username.text withpassword:self.password.text completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) -(void)checkcredentialswithusername:(nsstring *)username withpassword:(nsstring *)password completionhandler:(void (^)(nsdata *data,nsurlresponse *response, nserror *error))mycompletion { nsstring *requeststring = @"some website"; nsurl *url = [nsurl urlwithstring:requeststring]; nsurlrequest *req = [nsurlrequest requestwithurl:url]; nsdata *userpassworddata = [[nsstring stringwithformat:@"%@:%@", username, password] datausingencoding:nsutf8stringencoding]; nsstring *base64encodedcredential = [userpassworddata base64encodedstringwithoptions:0]; nsstring *authstring = [nsstring stringwithformat:@"basic %@", base64encodedcredential]; nsurlsessionconfiguration *sessionconfig=[nsurlsessionconfiguration defaultsessionconfiguration]; sessionconfig.httpadditionalheaders=@{@"authorization":authstring}; self.session=[nsurlsession sessionwithconfiguration:sessionconfig]; nsurlsessiondatatask *datatask = [self.session datataskwithrequest:req completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { mycompletion(data, response, error); }]; [datatask resume]; }
i'm stuck right , not sure issue since don't keyboard. have feeling there issue blocks i'm not sure issue is. help appreciated.
hey had same issue after received response web call. able solve doing following:
//do response
dispatch_async(dispatch_get_main_queue()) { () -> void in
// go on programme calling next step on main thread
}
i think if force next view controller ios attempts on not main thread, causing error, i'm not 100% is accurate
ios objective-c multithreading objective-c-blocks
No comments:
Post a Comment