加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – UIApplication openURL:不适用于相对URL

发布时间:2020-12-16 07:01:01 所属栏目:百科 来源:网络整理
导读:这是代码: NSURL *newsUrl = [NSURL URLWithString:@"/Document/News/1593" relativeToURL:[NSURL URLWithString:@"http://exist.ru"]];// Outputs "http://exist.ru/Document/News/1593"NSLog(@"%@",[newsUrl absoluteString]);// works[[UIApplication sh
这是代码:

NSURL *newsUrl = [NSURL URLWithString:@"/Document/News/1593" relativeToURL:[NSURL URLWithString:@"http://exist.ru"]];

// Outputs "http://exist.ru/Document/News/1593"
NSLog(@"%@",[newsUrl absoluteString]);

// works
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[newsUrl absoluteString]]];

// doesn't work
//[[UIApplication sharedApplication] openURL:newsUrl];

这是Apple的错误吗?

解决方法

在我的NSLog的Xcode输出中(@“NEW%@”,newsUrl)我将newUrl声明为

NSURL *newsUrl = [NSURL URLWithString:@"/Document/News/1593" relativeToURL:[NSURL URLWithString:@"http://exist.ru"]]:

NSLog输出是

/Document/News/1593 -- http://exist.ru

但对于[newsUrl absoluteString]

NSLog输出是

http://exist.ru/Document/News/1593

所以我猜[URLWithString:relativeToURL:]正在以不同的格式提供URL.这是您的结果无效的原因.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读