Reputation: 6824
I have made a login form in html/javascript to be injected into a UIWebView in my iPhone application. This all works really well and the login works. But when I press the login button it goes to the expected page within that view.
I was wondering if I could inject some objective c or by ways of a javascript do a modalView or dismissView to have upon the login have the page go to the application.
In the Application I have just made the UI of the webpage more user friendly.
So to kind of show what I am asking I have pasted some code.
NSString *myHTML = @"<form action="gotowebsite.com" onSubmit='return !validateLogin();'><input some textfield><input password field>";
Now I am imagining that the dismissal code will go into the onSubmit area.
Am I on a possibly good track??
Cheers Jeff
Upvotes: 0
Views: 421
Reputation: 3547
Implement UIWebViewDelegate
in your class and on successful login redirect your page to a url like login://success
when you redirect your page, UIWebview will start loading request and the call the function written below.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
NSURL *url = [request URL];
NSString *urlStr = [url absoluteString];
if([urlStr isEqualToString:@"login://success"]){ //same url which you gave for redirection
[self dismissModalViewControllerAnimated:YES]; // or do whatever you want to do on a successful login
}
return YES;
}
Upvotes: 4