0

発生している問題・エラーメッセージ

Swift で Firebase を使って画像を表示するアプリを作っているのですが、シミュレータでは画像が表示されるのですが、実機では何も表示されません。(tableView に画像を表示しています)
実機は iPhone を使っています。

実機で動かす場合は他に設定が必要なのでしょうか?

実行時のメッセージ:
実行時のメッセージ


該当のソースコード

appDelegateの記述

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
}

読み込み処理

import UIKit
import Firebase
import FirebaseDatabase
import FirebaseStorage

class SubViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource{


    var ref: DatabaseReference!

override func viewDidLoad() {
    super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self
        ref = Database.database().reference()

        var i : Int = -1
        ref.child(selectedNo!).observeSingleEvent(of: .value, with: { (snapshot) in
            for folder in snapshot.children {
                i += 1
                if let snap = folder as? DataSnapshot {
                    let dic = snap.value as! NSDictionary
                    self.elements.append(dic["image"] as! String)
                }
            }
            self.tableView.reloadData()
        }) { (error) in
            print(error.localizedDescription)
        }
}

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
        var imageRef: StorageReference {
            return Storage.storage().reference().child("images")
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as!
        SubCustomTableViewCell
        cell.Earthlbl.text = comments[indexPath.row]
            let downloadImageref = imageRef.child(elements[indexPath.row])
            let downloadtask = downloadImageref.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
                if let data = data {
                    cell.Earthimge.image = UIImage(data: data)
                    self.nextImage = UIImage(data: data)
                    self.elementsImage[indexPath.row] = UIImage(data: data)!
                }
                print(error ?? "NO ERROR")
            }
            downloadtask.observe(.progress) { (snapshot) in
                print(snapshot.progress ?? "NO MORE PROGRESS")
            }
        return cell
    }
4
  • 2
    シミュレータでのみ期待した通りに動くという場合は、絶対パスでホスト(Mac)のファイルを参照している、大文字小文字が間違っているなどがよくある理由として考えられます。いずれにしても、情報が足りないので、画像を表示している部分のコード、画像を読み込んでいる部分のコードなどを追記してください。 2018年6月17日 15:04
  • 実機テストの時、ref.child(selectedNo!).observeSingleEvent(of: .value, with: { (snapshot) inこの処理以降をしません。GoogleService-Info.plistもあります。
    – tamatw2020
    2018年6月18日 9:37
  • シミュレータの場合、netのケーブルを外すと画像が表示されないので、firebaseはnet上のdatabaseを読み込んでいると思います。
    – tamatw2020
    2018年6月18日 9:57
  • ログイン認証はしていませんが,それが原因でしょうか?
    – tamatw2020
    2018年6月19日 1:12

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。