gpt4 book ai didi

ios - 来自太多请求的 NSURLSession 和地理编码器错误,解决方案是什么?

转载 作者:行者123 更新时间:2023-11-29 01:05:03 28 4
gpt4 key购买 nike

每当用户使用我的应用进行搜索时,它都会返回最多包含 100 个结果的数组。我需要对每个索引进行地理编码(我在每个索引处都有纬度和经度),并在 map 上放置一个标记。

我还需要使用 NSURLSession 显示 https。然后我在指定的标记位置显示每个图像。对于较低的数字,一切都“正常”,但是我遇到了两个重大错误:

1)对于图像内容:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2) 对于地理编码器:

geoCoder error probably too many requests Optional(Error Domain=kCLErrorDomain Code=2 "(null)")

我猜我做的请求太多了,苹果有限制。那么我该如何解决这个问题呢?肯定有办法做到这一点,或者可能有不同的方法?这是显示图像的代码:

extension UIImageView {
public func imageFromUrl(urlString: String) {
if let url = NSURL(string: urlString) {
let request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
(response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in
if let imageData = data as NSData? {
self.image = UIImage(data: imageData)
}
}
}
}
}

这是地理编码器的代码:

for i in (0 ..< tbc.categorizedArray.count) {

//make sure that the specified index actually has a geoLon and geoLat
if var longitude :Double = tbc.categorizedArray[i]["geoLon"] as? Double {
longitude = tbc.categorizedArray[i]["geoLon"] as! Double
let latitude :Double = tbc.categorizedArray[i]["geoLat"] as! Double

//if it does, save it's location
let location = CLLocation(latitude: latitude, longitude: longitude)

//reverseGeoCode it's location
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {
placemarks, error in
if error != nil {
print("geoCoder error probably too many requests \(error)")
return
}

//place the markers
if let placemarks = placemarks {
let placemark = placemarks[0]
// Add annotation
let annotation = MKPointAnnotation()
annotation.title = tbc.categorizedArray[i]["screenname"] as? String
annotation.subtitle = tbc.categorizedArray[i]["userPost"] as? String
if let location = placemark.location {
annotation.coordinate = location.coordinate
// Display the annotation
self.mapView.showAnnotations([annotation], animated: true)
self.mapView.selectAnnotation(annotation, animated: true)
}
}
})
}

最佳答案

-9802 是应用程序传输安全问题。检查您的证书。

不知道地理编码器问题。

关于ios - 来自太多请求的 NSURLSession 和地理编码器错误,解决方案是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36513366/

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