开发者

getting warning with this link of code

开发者 https://www.devze.com 2023-01-31 09:41 出处:网络
-(CLLocationCoordinate2D) addressLocation { NSString *urlString = [NSString stringWithFormat:@\"http://maps.google.com/maps/geo?q=%@&output=csv\",
 -(CLLocationCoordinate2D) addressLocation {

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
   [address stringByAddingPercentEscapesUsingEncod开发者_如何学Cing:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSLog(@"locationString %@",locationString);
    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];
        NSLog(@"listItems %@",[listItems objectAtIndex:2]);
    }
    else {
        //Show error
    }
    CLLocationCoordinate2D location;
    location.latitude = latitude;
    location.longitude = longitude;

    return location;
}

StringWithContentsOfURL is deprecated....


try instead of: NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];

NSData *locationData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
NSString *locationString = [[NSString alloc] initWithData:locationData encoding:NSASCIIStringEncoding];

the good thing about this way is that you can use NSURLConnection instead to get the data (asynchronously).


If what made you confused is this "StringWithContentsOfURL is deprecated". A quick search in Apple's documentation shows that:

stringWithContentsOfURL: Returns a string created by reading data from the file named by a given URL. (Deprecated in iOS 2.0. Use stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error: instead.)

An example would be:

stringWithContentsOfURL:yourURL encoding:NSUTF8StringEncoding error:NULL
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号