将目标c注入UIWebView

发布于 2024-12-12 00:05:53 字数 523 浏览 0 评论 0原文

我已经用 html/javascript 制作了一个登录表单,将其注入到我的 iPhone 应用程序中的 UIWebView 中。这一切都运行得非常好并且登录有效。但是,当我按下登录按钮时,它会转到该视图中的预期页面。

我想知道是否可以注入一些 Objective C 或通过 javascript 执行 modalView 或 DismissView 以便在登录时将页面转到应用程序。

在应用程序中,我刚刚使网页的 UI 更加用户友好。

因此,为了展示我要问的内容,我粘贴了一些代码。

NSString *myHTML = @"<form action="gotowebsite.com" onSubmit='return !validateLogin();'><input some textfield><input password field>";

现在我想象解雇代码将进入 onSubmit 区域。

我可能走在一条好的轨道上吗?

干杯杰夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫罗兰の梦幻 2024-12-19 00:05:53

在您的类中实现 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;   
}

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;   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文