swift - 获取线程:信号 SIGABRT
问题描述
构建具有聊天功能的应用程序并收到 SIGBRT 错误。它似乎没有与 Firebase 数据库对话。我检查了我所有的插座,它们似乎都完好无损,我没有看到任何破损的插座。
我在调试区域遇到的错误是
“2018-08-21 01:09:15.479487-0400 拆分应用程序 [83668:9375919] *** 由于未捕获的异常“FIRAppNotConfigured”而终止应用程序,原因:“无法获取默认 Firebase 数据库实例。必须调用
[FIRApp configure]
(FirebaseApp.configure()
在 Swift 中)在使用 Firebase 数据库之前...... libc++abi.dylib:以 NSException 类型的未捕获异常终止”
class DataService{
static let dataService = DataService()
private var _BASE_REF = Database.database().reference()
private var _ROOM_REF = Database.database().reference().child("rooms")
var BASE_REF: DatabaseReference {
return _BASE_REF
}
var ROOM_REF:DatabaseReference{
return _ROOM_REF
}
var storageRef: StorageReference{
return Storage.storage().reference()
}
var fileURL: String!
// store the thumbnail in database
func CreateNewRoom(user: User, caption: String, data: NSData){
let filePath = "\(user.uid)/\
(Int(NSDate.timeIntervalSinceReferenceDate))"
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.child(filePath).putData(data as Data, metadata: metaData){
(metadata, error) in if error != nil {
print ("Error Uploading: \(String(describing:
error?.localizedDescription))")
return
}
//create a url for data (photo thumbnail image)
_ = metadata?.storageReference?.downloadURL(completion: error as!
(URL?, Error?) -> Void)
if Auth.auth().currentUser != nil {
let idRoom = self.BASE_REF.child("rooms").childByAutoId()
idRoom.setValue(["caption": caption,"thumbnailURLFromStorage":
self.storageRef.child(metadata!.path!).description, "fileURL" :
self.fileURL])
}
}
}
func fetchDataFromServer(callback: @escaping (Room) -> ()){
DataService.dataService.ROOM_REF.observe(.childAdded){ (snapshot) in
let room = Room(key: snapshot.key, snapshot: snapshot.value as!
Dictionary<String, Any>)
callback(room)
}
}
func SignUp(username:String, email: String, password: String, firstName:
String, lastName: String, data: NSData){
Auth.auth().createUser(withEmail: email, password: password, completion:
{ (user, error) in
if error != nil {
print(error!)
}
else {
print("Registration Successful")
}
let changeRequest =
Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = username
changeRequest?.commitChanges(completion: {(error) in
if let error = error {
print (error.localizedDescription)
return
}
})
let filePath = "profileimage/\(String(describing:
Auth.auth().currentUser!.uid))"
let metadata = FirebaseStorage.StorageMetadata()
metadata.contentType = "image/jpeg"
self.storageRef.child(filePath).putData(data as Data, metadata:
metadata, completion: {(metadata, error) in
if let error = error {
print ("\(error.localizedDescription)")
return
}
_ = metadata?.storageReference?.downloadURL(completion: error as!
(URL?, Error?) -> Void)
if let error = error {
print (error.localizedDescription)
return
}
else {
print ("Sweet!")
}
let appDelegate: AppDelegate = UIApplication.shared.delegate as!
AppDelegate
appDelegate.login()
})
}
}
解决方案
你应该按照这些步骤
第 1 步将 Firebase 导入您的 AppDelegate.swift
import Firebase
步骤 2在 AppDelegate.swift 中的 didFinishLaunchingWithOptions 方法中调用 configure()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
希望能帮助到你
推荐阅读
- php - 尝试在“mongodb”中使用 $or 运算符获取匹配值但未获取数据
- xaml - 除非我保存并重新加载,否则为什么我的图像直到我保存我的内容页面才绑定
- apache-spark-sql - 如何在 for 循环中使用 Spark 随后在数据集中添加列(其中 for 循环包含列名)
- mongodb - 在 Golang 中正确使用 Mongo
- c++ - 如何在 main 中定义一个常量并在其他头文件中使用它?
- file - 如何扫描 USB 连接中的文件?
- sql - 在 SQL 中查找特定值的具体数量
- java - 从引用路径 JAVA 的字符串中退出文本
- twitter - 有没有可能使用rest api在twitter中获取到给定日期的登录详细信息?
- python - Python打字,mypy根据类方法返回类型推断返回类型