###前提・実現したいこと
地図的なアプリを作っているのですが、ピンの画像を、FirebaseStorageに格納している個別の画像に変更したいです。
コードの前半部分は関係ないと思いますが、初心者でどこまでお見せすればよいかわからないため全体を公開します。
###発生している問題・エラーメッセージ
ピンの画像がデフォルトのまま変わりません。
画像の取得自体はうまくいっているようで、print(imageimage!)では格納している画像についての情報を読めるのですが、実際のピンはデフォルトのままです。
エラーメッセージを吐かないのでどう対策すればいいか悩んでいます。
###該当のソースコード
func pinCreate(){ //配列の該当のデータをitemという定数に代入? let items = contentArray //まずはFirebaseStorageに接続 let storage = Storage.storage() // Create a storage reference from our storage service let storageRef = storage.reference(forURL: "xxxx") for item in items { //itemの中身を辞書型に変換? let content = item.value as! Dictionary <String, Any> for (key, element) in content{ let pinData = content[key] as! [String: Any] if let geohash = pinData["geohash"] as? String { let (latitude, longitude) = Geohash.decode(hash: geohash)! let annotation = MKPointAnnotation() annotation.coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(latitude.min), CLLocationDegrees(longitude.min)) annotationArray.append(annotation) let reuseId = "pin" if var pinView = self.mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) { } else { // 再利用できるアノテーションが無い場合(初回など)は生成する var pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) // Firebase Storageの該当imageのReference let catRef = storageRef.child("xxxx.jpg") // Fetch the download URL catRef.downloadURL { (URL, error) -> Void in if (error != nil) { // Handle any errors } else { // Get the download URL for 'images/stars.jpg' // URLを指定したUIImageの生成例 let catPictureURL = URL! /* デフォルト設定でセッションオブジェクトを作成する。 */ let session = URLSession(configuration: .default) /* ダウンロードタスクを定義します。ダウンロードタスクは、 URLの内容をデータオブジェクトとしてダウンロードし、 そのデータで望むことを実行できます。 */ let downloadPicTask = session.dataTask(with: catPictureURL) { (data, response, error) in /* ダウンロードが完了しました。 */ if let e = error { print("pictureのダウンロード中にエラーが発生しました: \(e)") } else { /* エラーは見つかりませんでした。 レスポンスがないと変わってしまいますので、それもチェックしてください。 */ if let res = response as? HTTPURLResponse { print("\(res.statusCode)") if let imageData = data { /* 最後に、そのデータをイメージに変換し、 それを使って望むことをします。 */ let imageimage = UIImage(data: imageData) print(imageimage!) pinView.image = imageimage pinView.annotation = annotation } else { print("画像を取得できませんでした:画像はありません") } } else { print("何らかの理由で応答コードを取得できませんでした") } } } downloadPicTask.resume() } } } self.mapView.addAnnotations(annotationArray) } } } }
###補足情報(言語/FW/ツール等のバージョンなど)
swift3
xcode8.3.3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/01 03:05