错误:libc ++ abi.dylib:以类型为NSException的未捕获异常终止
当我尝试将图像上传到Firebase Storage
,然后使用图像的user
在Firebase Database
上创建url
时,我正在努力解密此错误的错误消息除了其他用户属性,还可以上传。
该应用程序崩溃并在下面显示控制台输出,--- 4
行未打印到控制台,因此表明.putData
调用不起作用。
任何帮助将不胜感激。
控制台输出:
Inside createFirebaseUser()
--- 1
--- 2
--- 3
libc++abi.dylib: terminating with uncaught exception of type NSException
功能
: fileprivate func createFirebaseUser(firebaseUserComplete: @escaping (_ status: Bool) -> ()){
print("Inside createFirebaseUser()")
let fileName = UUID().uuidString
print("--- 1")
guard let profilePic = self.profilePic else { return }
print("--- 2")
guard let uploadData = UIImageJPEGRepresentation(profilePic, 0.5) else { return }
print("--- 3")
StorageService.run.REF_STORAGE_USERSPICS.child(fileName).putData(uploadData, metadata: nil) { (metadata, error) in
if let error = error {
print("There is an error with putData: \(error)")
return
}//end if-let
print("--- 4")
StorageService.run.REF_STORAGE_USERSPICS.child(fileName).downloadURL(completion: { (url, error) in
guard let profilePicURL = url?.absoluteString else {
print("failed to get image URL: ", error!)
return
}//end guard-let
guard let uid = Auth.auth().currentUser?.uid else { return }
let signupTimeRef = String(Date.timeIntervalSinceReferenceDate)
let prefs = ["women": 0,
"men": 0,
"minAge": 18,
"maxAge": 49]
//building the values for the dictionary
let dictionaryValues = ["name": self.name!,
"email": self.email!,
"profilePictureURL": profilePicURL,
"firstName": self.firstName!,
"lastName": self.lastName!,
"gender": self.gender!,
"birthday": self.birthday!,
"signupTime": signupTimeRef,
"discoverable": true,
"online": true,
"lastOnline": ServerValue.timestamp(),
"discoveryPrefs": prefs] as [String : Any]
//combining both uid and dictionary values in readiness for user creation
let values = [uid: dictionaryValues]
//creating the user and passing its values
DataService.run.REF_USERS.updateChildValues(values, withCompletionBlock: { (error, reference) in
if let error = error {
firebaseUserComplete(false)
print (error)
return
}
firebaseUserComplete(true)
print ("Successfully saved user into Firebase database.")
})// end DataService.run.REF_USERS.updateChildValues
})//end .downloadURL
}////end .putData
}
完整错误日志:
2018-08-14 21:56:25.069011+0930 vipeeps[15149:7547021] *** Assertion failure in -[FIRStorageUploadTask enqueue], /Users/.../Pods/FirebaseStorage/Firebase/Storage/FIRStorageUploadTask.m:73
2018-08-14 21:56:25.071681+0930 vipeeps[15149:7547021] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Upload attempting to execute on non main queue! Please only execute this method on the main queue.'
*** First throw call stack:
(0x183b3ad8c 0x182cf45ec 0x183b3abf8 0x18452afa0 0x100428098 0x1004217c0 0x100256640 0x100255d8c 0x100255f98 0x1840c9dbc 0x1840e2adc 0x184562e88 0x1844a48d0 0x1844a3cac 0x1050e119c 0x1050ed7cc 0x1050e119c 0x1050ed7cc 0x1050ed6b0 0x184564750 0x1050e119c 0x1050ee454 0x1050ecd44 0x1050f27c8 0x1050f2500 0x18375ffac 0x18375fb08)
libc++abi.dylib: terminating with uncaught exception of type NSException
答案 0 :(得分:1)
将代码添加到主线程中,希望对您有所帮助
DispatchQueue.main.async {
//Your code
}