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

objective-c – UIApplication openURL:不适用于相对URL,第1张

概述这是代码: NSURL *newsUrl = [NSURL URLWithString:@"/Document/News/1593" relativeToURL:[NSURL URLWithString:@"http://exist.ru"]];// Outputs "http://exist.ru/Document/News/1593"NSLog(@"%@", [newsUrl absol 这是代码:

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.这是您的结果无效的原因.

总结

以上是内存溢出为你收集整理的objective-c – UIApplication openURL:不适用于相对URL全部内容,希望文章能够帮你解决objective-c – UIApplication openURL:不适用于相对URL所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1226193.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存