ios - Slow view switch using UIViewController -
i'm working on first app integrates web service. right have 2 views respective view controllers. have login view, users login app , verify , store there login credentials , have main view shows users info web service. 2 views work correctly individually after verifying credentials of user on login view want switch views login view. i'm using uiviewcontroller. here code when login button pressed:
-(ibaction)login:(id)sender{ //show network activity happening uiapplication *application = [uiapplication sharedapplication]; application.networkactivityindicatorvisible = yes; //validate credentials [_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) { //if successful status code save username , password in keychain. nslog(@"sucess"); nsdictionary *credentials = @{self.username.text: self.password.text}; [keychainuserpass save:@"insert app name here" data:credentials]; nslog(@"go new page"); //print response webservice debugging purposes nsmutabledictionary *jsonobject = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; nslog(@"%@", jsonobject); //switch new view controller uiviewcontroller *maincontroller = [[rdmainviewcontroller alloc] initwithnibname:@"rdmainviewcontroller" bundle:nil]; [self.navigationcontroller pushviewcontroller:maincontroller animated:no]; } else{ //error case, handle it. nslog(@"error"); } } else{ //error case, handle it. nslog(@"error"); } }]; } and here checkcredentialswithusername method:
-(void)checkcredentialswithusername:(nsstring *)username withpassword:(nsstring *)password completionhandler:(void (^)(nsdata *data,nsurlresponse *response, nserror *error))mycompletion { //create request url nsstring *requeststring = @"web_service_url"; nsurl *url = [nsurl urlwithstring:requeststring]; nsurlrequest *req = [nsurlrequest requestwithurl:url]; //store password , user name authentication nsdata *userpassworddata = [[nsstring stringwithformat:@"%@:%@", username, password] datausingencoding:nsutf8stringencoding]; nsstring *base64encodedcredential = [userpassworddata base64encodedstringwithoptions:0]; nsstring *authstring = [nsstring stringwithformat:@"basic %@", base64encodedcredential]; //create nsurl session 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]; } my issue it's taking incredibly long time switch views. on minute. @ first thought network connection printed info receiving web service , appearing quickly. after printed info still taking long time views switch. i'm not sure why think has way i'm doing blocks. thought why it's taking me such long time switch views?
any help appreciated.
@danyun right. needed following:
if (httpresp.statuscode == 200) { //if successful status code save username , password in keychain. nslog(@"sucess"); nsdictionary *credentials = @{self.username.text: self.password.text}; [keychainuserpass save:@"insert app name here" data:credentials]; nslog(@"go new page"); //print response webservice debugging purposes nsmutabledictionary *jsonobject = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; nslog(@"%@", jsonobject); [[nsoperationqueue mainqueue] addoperationwithblock:^{ //test create sure on main queue ui update //switch new view controller uiviewcontroller *maincontroller = [[rdmainviewcontroller alloc] initwithnibname:@"rdmainviewcontroller" bundle:nil]; [self.navigationcontroller pushviewcontroller:maincontroller animated:no]; }]; } ios objective-c uiviewcontroller block
No comments:
Post a Comment