每当用户使用我的应用进行搜索时,它都会返回最多100个结果的数组。我需要对每个索引进行地理编码(每个索引都有lat和lon),然后在地图上放置一个标记。

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

1)对于图片素材:

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


2)对于地理编码器:

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


我的猜测是我提出的要求太多,而Apple有一个限制。那么我该如何解决呢?当然有办法做到这一点,或者也许是另外一种方法?这是显示图像的代码:

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是应用程序传输安全性问题。检查您的证书。

不知道地址解析器的问题。

10-08 07:46