iOS - UIWebView - 需要提交表单才能在 Safari 中打开
我一直在为 iOS
平台开发 HTML5
/ Javascript
网络应用程序。我对 Objective 和 XCode 比较陌生,但我了解该程序的方法。我试图让 UIWebView 打开一个表单,一旦在 Safari 中提交(提交按钮),而不是在当前的 UIWebView 中打开它。
建议使用以下代码在 Safari 中打开标准 标签:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
(原始帖子 此处 )
我尝试专门针对提交的表单调整此代码,如下所示:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeFormSubmitted ) {
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
if ( inType == UIWebViewNavigationTypeFormResubmitted ) {
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
return YES;
}
仅供参考,我已将每个 IF 语句的返回值切换为 YES / NO,但这并不似乎是问题......有什么想法吗?代码?理论? 谢谢!
I have been developing an HTML5
/ Javascript
webapp for the iOS
platform. I am relatively new to Objective and XCode, but I know my way around the program. I am attempting to have the UIWebView open a form, once submitted (submit button) in Safari as opposed to opening it in the current UIWebView.
The code below is suggested for opening standard <a>
tags in Safari:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
( original post here )
I have tried adapting this code specifically for submitted forms like so:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeFormSubmitted ) {
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
if ( inType == UIWebViewNavigationTypeFormResubmitted ) {
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
return YES;
}
And FYI I have switched the return values of each IF statement to YES / NO, however this doesn't seem to be the issue... Any thoughts? Code? Theory? Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下实现了我正在寻找的“在 Safari 中打开”结果。
首先,我通过将
webView.delegate = self;
添加到我的viewDidLoad
声明中来实现UIWebViewDelegate
协议:appViewController.m
其次,我添加了以下
内容:一点令人好奇的是 XCode 返回了以下警告标志:
不知道为什么......但是!该应用程序现在会在 Safari 中打开提交表单的结果。
The following achieved the "Open in Safari" result I was looking for.
First I implemented
UIWebViewDelegate
protocol by addingwebView.delegate = self;
to myviewDidLoad
declaration:appViewController.m
Secondly I added the following:
One point of curiosity was that XCode returned the following warning flag:
Not sure why... but! The app now opens the results of the submitted form in Safari.