[英]How can i replace this statement in ios5
當我寫“ 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]];
它已被替換為
stringWithContentsOfURL:encoding:error:
要么
stringWithContentsOfURL:usedEncoding:error:
范例程式碼
NSError* error = nil;
NSString* locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
檢查文檔中的stringWithContentsOfURL。 在NSString文檔中,它准確地告訴您使用什么方法來替換不推薦使用的方法,並且很高興知道如何做,因為您經常會檢查此類內容的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.