gpt4 book ai didi

swift - 获取线程: signal SIGABRT

转载 作者:行者123 更新时间:2023-11-30 11:13:37 25 4
gpt4 key购买 nike

构建具有聊天功能的应用程序并收到 SIGBRT 错误。它似乎没有与 Firebase 数据库对话。我检查了所有 socket ,它们似乎都完好无损,没有看到任何损坏的 socket 。

我在调试区域遇到的错误是

"2018-08-21 01:09:15.479487-0400 Split App[83668:9375919] *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'Failed to get default Firebase Database instance. Must call [FIRApp configure] (FirebaseApp.configure() in Swift) before using Firebase Database.... libc++abi.dylib: terminating with uncaught exception of type 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
}

希望对你有帮助

关于swift - 获取线程: signal SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51942021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com