• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iPhone:UIWebview 在 safari 中打开超链接

[复制链接]
菜鸟教程小白 发表于 2022-12-11 22:06:06 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在我的应用程序中,我使用了 UIwebview,我需要在其中超链接一些电话号码、电子邮件和 URL。我做了以下操作:

 - (void)viewDidLoad
    {
        credits.delegate=self;
    }



-(void)loadScreen
{
scroll=[[UIScrollView alloc]init];
 credits=[[UIWebView alloc]init];

NSString *Address = @"www.***.com/php/getjson.php?method=";


    jmax = [NSURL URLWithString:Address];

    NSData *Data =[ NSData dataWithContentsOfURL:jmax];


    String = [[NSString alloc] initWithDataata encoding:NSUTF8StringEncoding];

    NSString * creditsHtml = [NSString stringWithFormat" <font face=\"Arial\"><H3 align=\"center\"> Credits </H3> %@ <br>hone%@</font>", String,phone];

    credits.userInteractionEnabled = YES;
    credits.frame=CGRectMake(10, (frame1.size.height + 564), 300, 100);
    credits.dataDetectorTypes=UIDataDetectorTypeAll;
    credits loadHTMLString:creditsHtml baseURL:nil];

[scroll addSubview:credits];
}



   -(BOOL)webViewUIWebView*)webView shouldStartLoadWithRequestNSURLRequest*)request navigationTypeUIWebViewNavigationType)navigationType{


        NSString *urls=  jmaxString;

        NSURL *requestURL =[NSURL URLWithString: urls]; 
        if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ] ) 
            && ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) { 
            return ![ [ UIApplication sharedApplication ] openURL: requestURL ]; 
        } 

        return YES; 
    }

编辑 shouldStartLoadWithRequest: 方法

-(BOOL)webViewUIWebView*)webView shouldStartLoadWithRequestNSURLRequest*)request navigationTypeUIWebViewNavigationType)navigationType{

    NSURL *requestURL =[request URL];

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

NSURL *requestURL =[request URL]; 出现错误,Expected ;在末尾 & Extraneous ')' before ';'



Best Answer-推荐答案


您在 loadScreen 函数中分配/初始化 UIWebView 的一个新对象,而没有设置其委托(delegate),因为您假设您在 viewDidLoad 中这样做了。您必须在定义实例“信用”后设置委托(delegate)。

关于iPhone:UIWebview 在 safari 中打开超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9703175/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap