Reputation: 1217
ERROR: libc++abi.dylib: terminating with uncaught exception of type NSException
I am struggling to decipher this cryptic error message when I try to upload an image to Firebase Storage
and then create a user
on Firebase Database
using the url
of the image uploaded in addition to other user attributes.
The app crashes and shows the console output below, the line --- 4
does not print to the console so it indicates that the .putData
call is not working.
Any help would be appreciated.
Console output:
Inside createFirebaseUser()
--- 1
--- 2
--- 3
libc++abi.dylib: terminating with uncaught exception of type NSException
Function:
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
}
Full error log:
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
Upvotes: 0
Views: 283
Reputation: 3907
add your code inside a main thread hope it's help
DispatchQueue.main.async {
//Your code
}
Upvotes: 1