Firebase存储完成功能永远不会触发/被回调

时间:2019-06-09 09:06:10

标签: ios swift firebase firebase-storage

当我尝试将图像上传到Firebase Storage时遇到奇怪的问题。从本质上讲,我能够将文件上传到存储,但是完成回调并未发生。我需要此回调来获取要上传文件的存储URL。

设置

let storage = Storage.storage()
let storageRef = storage.reference()
let data = curImg?.pngData()
let riversRef = storageRef.child("userUploads/Search/"+id+".png")

上传功能

let uploadTask = riversRef.putData(data!, metadata: nil) { (metadata, error) in
    print("FIN") // NEVER PRINTS
    print("DONE",metadata,error) // NEVER PRINTS
}
  

这永远不会打印任何东西

使用观察

uploadTask.observe(.success) { snapshot in
    // Upload completed successfully
    print("SUCCESS") // NEVER PRINTS
    riversRef.downloadURL(completion: { (url, error) in
        print("A") // NEVER PRINTS
        print(url,error) // NEVER PRINTS
    })
}
  

这永远不会打印任何东西

一点点麻烦

uploadTask.observe(.progress) { snapshot in
    print(snapshot) // PRINTS!
    if (Double(snapshot.progress!.completedUnitCount) == Double(snapshot.progress!.totalUnitCount)) {
        print("HERE") // PRINTS!!
        riversRef.downloadURL(completion: { (url, error) in
            print("B") // NEVER PRINTS
            print(url,error) // NEVER PRINTS
        })
    }
}
  

能够打印进度,并且能够弄清楚进度最终何时完成,但是我永远无法获得downloadURL来完成:(

编辑,我尝试更新pod并重新安装所有组件,但没有帮助。

1 个答案:

答案 0 :(得分:0)

如果遇到这个奇怪的问题,则代码没有错。我必须使用WRAP_CONTENT删除<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="120dp" android:background="#edf0f4" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="0dp" android:layout_weight="70" android:layout_height="match_parent" android:background="#edf0f4" android:id="@+id/LayoutSettingName"> <TextView android:text="Dark Theme" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txtSettingName" android:textColor="#000000" android:autoSizeMaxTextSize="20dp" android:autoSizeMinTextSize="17dp" android:autoSizeTextType="uniform" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:textStyle="bold" /> <TextView android:text="Change the theme to something more dark" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/txtSettingDescription" android:textColor="#666666" android:autoSizeMaxTextSize="18dp" android:autoSizeMinTextSize="16dp" android:autoSizeTextType="uniform" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_weight="30" android:layout_height="match_parent" android:background="#edf0f4" android:id="@+id/LayoutSettingValue" android:gravity="center"> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:background="#dddddd" android:textColor="#FFFFFF" android:id="@+id/SettingEditText" /> <Spinner android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/SettingSpinner" /> <Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="25px" android:minHeight="25px" android:id="@+id/SettingSwitch" /> </LinearLayout> </LinearLayout> </LinearLayout> 来回滚所有pod。最新版本的Firebase / Xcode中的怪异错误??