简体   繁体   English

通过此代码链接获得警告

[英]getting warning with this link of code

 -(CLLocationCoordinate2D) addressLocation {

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
   [address stringByAddingPercentEscapesUsingEncoding: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.... 不推荐使用StringWithContentsOfURL。...

If what made you confused is this "StringWithContentsOfURL is deprecated". 如果让您感到困惑的是,此“不推荐使用StringWithContentsOfURL”。 A quick search in Apple's documentation shows that: 在Apple文档中的快速搜索显示:

stringWithContentsOfURL : Returns a string created by reading data from the file named by a given URL. stringWithContentsOfURL :返回一个字符串,该字符串是通过从给定URL命名的文件中读取数据而创建的。 ( Deprecated in iOS 2.0 . Use stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error: instead.) 在iOS 2.0中已弃用改为使用stringWithContentsOfURL:encoding:error:stringWithContentsOfURL:usedEncoding:error:。

An example would be: 一个例子是:

stringWithContentsOfURL:yourURL encoding:NSUTF8StringEncoding error:NULL

try instead of: NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; 尝试而不是: 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). 这种方式的好处是,您可以改用NSURLConnection来获取数据(异步)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM