iphone - 我怎样才能在ios5中替换这个语句

标签 iphone ios

当我写“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];

关于iphone - 我怎样才能在ios5中替换这个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306018/

相关文章:

iphone - MFMailComposeViewController 的发送和取消按钮未出现

ios - 在表格 View 单元格中显示图像

iOS - 执行 block 后从 heightForRowAtIndexPath 返回值

iphone - 关于 NSData 的不明确信息 - Objective C/Xcode

IOS不同的xib适用于不同的屏幕尺寸

ios - 推送通知在 TestFlight 上不起作用

ios - UITableViewCell 中的 UITableView 是解决我的问题的好方法吗?

iphone - 学习 OpenGL ES 1.x

iphone - iOS - 将已安装的证书从钥匙串(keychain)附加到请求

iphone - 根据日期设置 Alpha