ios - Get current webview URL and login -


i try current url because when put bad login in app, have login page displayed. don't want page displayed. so, use solution current url , if url http://www.example.com/account/login/ want create action. currently, when try solution, have null response.

 nsstring * currenturl = _loadscreen.request.url.absolutestring;     if ([currenturl isequaltostring:@"http://www.example.com/account/login/"]) {         nslog(@"warning");     }     else     {         nslog(@"url %@",currenturl); <- return (null).     } 

i use code auto-login users :

nsstring *identifiant = [[nsuserdefaults standarduserdefaults] valueforkey:@"identifiant"];     nsstring *password = [[nsuserdefaults standarduserdefaults] valueforkey:@"password"];     if((identifiant) && (password))     {         //configure url         nsstring* host = @"http://www.example.com";         nsstring* complement = @"/account/login";            nsstring* user_name = [[nsuserdefaults standarduserdefaults] valueforkey:@"identifiant"];         nsstring* password = [[nsuserdefaults standarduserdefaults] valueforkey:@"password"];         //add url + folder         nsstring *urlstring = [nsstring stringwithformat:@"%@%@", host, complement];           //nsurl *url = [nsurl urlwithstring:urlstring];         nsurl *url = [nsurl urlwithstring:urlstring];           //nsurlrequest *request = [nsurlrequest requestwithurl:url];          //add informations post         nsstring *post = [nsstring stringwithformat:@"user_name=%@&password=%@&submit=submit", user_name, password];;           nsdata *postdata = [post datausingencoding:nsasciistringencoding allowlossyconversion:yes];          nsstring *postlength = [nsstring stringwithformat:@"%lu", (unsigned long)[postdata length]];         nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];         [request sethttpmethod:@"post"];         [request setvalue:postlength forhttpheaderfield:@"content-length"];         [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];         [request sethttpbody:postdata];           nsoperationqueue *queue = [[nsoperationqueue alloc] init];            [nsurlconnection sendasynchronousrequest:request queue:queue completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error)          {              if ([data length] > 0 && error == nil) [_loadscreen loadrequest:request];              else if (error != nil) nslog(@"error: %@", error);          }];     }     else     {       uiviewcontroller *controller = [self.storyboard instantiateviewcontrollerwithidentifier:@"login"];     [self presentviewcontroller:controller animated:yes completion:nil];     }     nsstring * currenturl = _loadscreen.request.url.absolutestring;     if ([currenturl isequaltostring:@"http://www.example.com/account/login/"]) {         nslog(@"warning");     }     else     {         nslog(@"url %@",currenturl);     } 

it's work fine, if user put id, if not, login page displayed don't want.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -