0

I am having trouble implement this.

Theres a UIwebview that holds a site which required to login. I first created a login modal page for the user to login, and this part is DONE.

I used the code from here: How to display the Authentication Challenge in UIWebView?

Now, once the user logged in, he/she is sitting inside the secured mobile site. But there are some links in the mobile site which requires to login again.

Right now I am doing it in a hacky way, in the method of:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

I check and see if the request.url is equal to "https://www.#$%^&.com", if yes, then i will set _authed = NO, and basically do the login process again.

It works fine, but if there are 100+ of links that required to logins again, I will have to add 100+ of url to my if-statement, in order to catch it.

I am hoping someone can help me figure out a better way to implement this.

Community
  • 1
  • 1
BlackCat
  • 33
  • 5

1 Answers1

0

You can write javascript function in your web page and call login method from there. you just need to pass username and password from modal page. Execute javascript in webViewDidFinishLoad like below

[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"DoLogin('%@','%@','%@');",username,password,redirectURL];
Paras Gandhi
  • 823
  • 1
  • 13
  • 28
  • Hi, what is that "redirectURL"? – BlackCat Apr 15 '13 at 21:33
  • if you want to redirect any other page except home page like in my example, after login i am redirecting to settings page. its not just parameter of my function – Paras Gandhi Apr 16 '13 at 04:43
  • hmmm, i dont think it works, cuz webviewdidFinishLoad will get never called when I click a link that requires NTLM authentication. webview did start, but never finished – BlackCat Apr 16 '13 at 13:30