gpt4 book ai didi

ios - '初始化(contentsOfURL :)' is unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift

转载 作者:行者123 更新时间:2023-11-28 13:20:54 27 4
gpt4 key购买 nike

我找不到 contentsOfURL 的任何替代方法来解决此问题。

这是我的 Swift 代码:

import Foundation
import MapKit

class MapHelper{


func geoCodeUsingAddress(address:String) ->CLLocationCoordinate2D{
var latitude = 0.0
var longitude = 0.0
let esc_addr = address.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
let req = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=\(esc_addr)"

let result:NSString? = NSString(contentsOfURL: NSURL(string: req)); // here is error //msg comes

if let value=result{
let scanner:NSScanner = NSScanner(string: value)
if(scanner.scanUpToString("\"lat\" :", intoString: nil) && scanner.scanString("\"lat\" :", intoString: nil)){
scanner.scanDouble(&latitude)
}
if(scanner.scanUpToString("\"lng\" :", intoString: nil) && scanner.scanString("\"lng\" :", intoString: nil)){
scanner.scanDouble(&longitude);
}
}
else{

}

var center:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0);
center.latitude = latitude;
center.longitude = longitude;
return center;

}
}

最佳答案

试试这个

let urlPath: String = "YOUR URL HERE"
let data = NSString(contentsOfURL: urlPath, encoding: NSASCIIStringEncoding, error: nil)

关于ios - '初始化(contentsOfURL :)' is unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25910259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com