Swift Error: NSInternalInconsistencyException, 'Upload attempting to execute on non main queue! Onl



我正在我的应用程序(使用TwitterKit(上实现使用Twitter登录选项,但它在以下功能上不断崩溃 - 保存UserIntoFirebase数据库(上传用户数据时,图像到Firebase数据库(。我不明白如何或为什么下面的函数需要在主队列中?

用户数据被获取并保存到Firebase Auth部分,但是当尝试将用户数据保存到实时数据库和存储时,它似乎崩溃了?

fileprivate func saveUserIntoFirebaseDatabase() {
guard let uid = Auth.auth().currentUser?.uid,
let name = self.name,
let username = self.username,
let email = self.email,
let profileImage = profileImage,
let profileImageUploadData = UIImageJPEGRepresentation(profileImage, 0.3) else { Service.dismissHud(self.hud, text: "Error", detailText: "Failed to save user.", delay: 3); return }
let filename = UUID().uuidString
let storageRef = Storage.storage().reference().child("profile_images").child(filename)
storageRef.putData(profileImageUploadData, metadata: nil, completion: { (metadata, err) in
if let err = err {
Service.dismissHud(self.hud, text: "Error", detailText: "Failed to save user with error: (err)", delay: 3);
return
}
// Firebase 5 Update: Must now retrieve downloadURL
storageRef.downloadURL(completion: { (downloadURL, err) in
guard let profileImageUrl = downloadURL?.absoluteString else { return }
print("Successfully uploaded profile image into Firebase storage with URL:")
let dictionaryValues = ["name": name,
"email": email,
"username": username,
"profileImageUrl": profileImageUrl]
let values = [uid : dictionaryValues]
Database.database().reference().child("users").updateChildValues(values, withCompletionBlock: { (err, ref) in
if let err = err {
Service.dismissHud(self.hud, text: "Error", detailText: "Failed to save user info with error: (err)", delay: 3)
return
}
print("Successfully saved user info into Firebase database")
// after successfull save dismiss the welcome view controller
self.hud.dismiss(animated: true)
self.dismiss(animated: true, completion: nil)
})
})
})
} 

我设置的 MainTabBar 控制器具有以下内容,以查看当前用户是否已登录,如果没有,他们将被重定向到欢迎控制器。这可能是原因吗?

fileprivate func checkLoggedInUserStatus() {
if Auth.auth().currentUser == nil {
DispatchQueue.main.async {
let welcomeController = WelcomeController()
let welcomeNavigationController = UINavigationController(rootViewController: welcomeController)
self.present(welcomeNavigationController, animated: false, completion: nil)
return
}
}
}

我认为您正在尝试在后台线程上关闭视图控制器。

相关内容

最新更新