iPhone:UIWebview 在 safari 中打开超链接
<p><p>在我的应用程序中,我使用了 UIwebview,我需要在其中超链接一些电话号码、电子邮件和 URL。我做了以下操作:</p>
<pre><code> - (void)viewDidLoad
{
credits.delegate=self;
}
-(void)loadScreen
{
scroll=[init];
credits=[init];
NSString *Address = @"www.***.com/php/getjson.php?method=";
jmax = ;
NSData *Data =[ NSData dataWithContentsOfURL:jmax];
String = [ initWithData:Data encoding:NSUTF8StringEncoding];
NSString * creditsHtml = ;
credits.userInteractionEnabled = YES;
credits.frame=CGRectMake(10, (frame1.size.height + 564), 300, 100);
credits.dataDetectorTypes=UIDataDetectorTypeAll;
credits loadHTMLString:creditsHtml baseURL:nil];
;
}
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *urls=jmaxString;
NSURL *requestURL =;
if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ] )
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
return ![ [ UIApplication sharedApplication ] openURL: requestURL ];
}
return YES;
}
</code></pre>
<p>编辑 shouldStartLoadWithRequest: 方法</p>
<pre><code>-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *requestURL =;
if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ] )
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
return ![ [ UIApplication sharedApplication ] openURL: requestURL ];
}
NSLog(@"URL %@",requestURL);
return YES;
}
</code></pre>
<p><code>NSURL *requestURL =;</code> 出现错误,<code>Expected ;在末尾</code> & <code>Extraneous ')' before ';'</code></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您在 loadScreen 函数中分配/初始化 UIWebView 的一个新对象,而没有设置其委托(delegate),因为您假设您在 viewDidLoad 中这样做了。您必须在定义实例“信用”后设置委托(delegate)。</p></p>
<p style="font-size: 20px;">关于iPhone:UIWebview 在 safari 中打开超链接,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/9703175/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/9703175/
</a>
</p>
页:
[1]