当我写'stringWithContentsOfURL'时,我收到'stringWithContentsOfURL已弃用'的错误。
-(CLLocationCoordinate2D) addressLocation
{
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
我该如何更换这条线。谢谢!
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
答案 0 :(得分:1)
已被
取代stringWithContentsOfURL:encoding:error:
或
stringWithContentsOfURL:usedEncoding:error:
示例代码
NSError* error = nil;
NSString* locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
答案 1 :(得分:0)
查看stringWithContentsOfURL的文档。在NSString文档中,它会告诉您确切地使用哪些方法来替换已弃用的方法,并且知道如何操作,因为检查这类内容的文档是您经常要做的事情。