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