gpt4 book ai didi

objective-c - UIApplication openURL : doesn't work with relative URLs

转载 作者:可可西里 更新时间:2023-11-01 06:11:31 26 4
gpt4 key购买 nike

代码如下:

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

是苹果的bug吗?

最佳答案

在我的 NSLog(@"NEW %@", newUrl) 的 Xcode 输出中,我将 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 : doesn't work with relative URLs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11969078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com