简体   繁体   English

将目标c注入UIWebView

[英]Inject objective c into UIWebView

I have made a login form in html/javascript to be injected into a UIWebView in my iPhone application. 我已经用html / javascript制作了一个登录表单,可以将其插入到iPhone应用程序的UIWebView中。 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. 我想知道是否可以注入一些目标c或通过javascript进行modalView或dismissView以便在登录时将页面转到应用程序。

In the Application I have just made the UI of the webpage more user friendly. 在应用程序中,我刚刚使网页的UI更加用户友好。

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. 现在,我正在想象解雇代码将进入onSubmit区域。

Am I on a possibly good track?? 我走上了一条好路吗?

Cheers Jeff 干杯杰夫

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. 在您的类中实现UIWebViewDelegate ,并在成功登录后将页面重定向到诸如login:// success之类的URL,当您重定向页面时,UIWebview将开始加载请求并调用下面编写的函数。

- (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;   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM