-2
返回nil,我面临着“NSURL URLWithString”方法的问题,“NSURL URLWithString”方法不适用于无效URL字符串
我期待得到在使用上述方法,如果该URL字符串无效为零。但它的返回空值。
我附上了下面的代码示例。
NSString *sampleURLString = @"";
NSURL *sampleURL = [NSURL URLWithString:sampleURLString];
NSLog(@"Sample url string : %@", sampleURLString);
NSLog(@"Sample url : %@", sampleURL);
其他信息:
- 我使用的XCode 8.1版。
- 我也在iOS版本 (8,9,10)中测试过设备和模拟器。
- 截至目前,我已经通过使用“canOpenURL”来检查结果NSURL并避免进一步执行。但我需要知道为什么会出现这个问题。
sampleURLString通过你的网址在这里 –
@HimanshuMoradiya:当通过任何URL,如 “http://www.google.com” “URLWithString” 功能是否正常工作,并返回一个有效的NSURL,但只有当我传递如上所示的空url字符串时,我不会像它应该那样得到零。 – Bharath
你在使用webview吗? –