2016-04-09 16 views
0

Bir kullanıcı benim uygulamamı kullanarak arama yaptığında, 100 sonuçtan oluşan bir dizi döndürür. Her dizini coğrafi olarak kodlamam gerekiyor (her dizinde enlem ve boylam var) ve haritaya bir işaretçi bırakıyorum.NSURLSession ve geocoder hataları çok fazla isteklerden kaynaklanıyor, çözüm nedir?

Ayrıca NSURLSession kullanarak bir https görüntülemem gerekiyor. Ardından, her görüntüyü belirlenen işaretçi konumunda görüntülerim.

1) resim şeyler için:

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

2) coğrafi kodlayıcısında için:

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

Benim tahminim Herşey ancak iki önemli hataları olsun, alt numaraları için "iyi" çalışıyor Çok fazla istek alıyorum ve elmanın bir kısıtlaması var. Peki bunu nasıl başarabilirim? Elbette bunu yapmanın bir yolu var mı, belki de farklı bir yöntem mi? İşte görüntüleri görüntülüyor kod şudur:

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) 
       } 
      } 
     } 
    } 
} 

Ve burada coğrafi kodlayıcısında kodudur:

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) 
          } 
         } 
        }) 
       } 

cevap

1

-9802 bir App Ulaşım Güvenliği sorundur. Sertifikanı kontrol et.

Coğrafi kod konusu hakkında bir fikir yok.