简体   繁体   English

为什么我的 iOS 应用程序没有写入 firestore 模拟器

[英]Why is my iOS app not writing to the firestore emulator

I am trying to setup a firebase emulator to simulate some actions in my iOS app.我正在尝试设置一个 firebase 模拟器来模拟我的 iOS 应用程序中的一些操作。 When I try to create a post to my emulated firestore I get the following error:当我尝试创建一个帖子到我的模拟 firestore 时,我收到以下错误:

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-12-10 17:55:48.513205-0500 Pikit[13139:100646] 6.25.0 - [Firebase/Firestore][I-FST000001] Listen for query at  failed: 
false for 'list' @ L6
Error Domain=FIRFirestoreErrorDomain Code=7 "
false for 'list' @ L6" UserInfo={NSLocalizedDescription=
false for 'list' @ L6}
Error writing document: Error Domain=FIRFirestoreErrorDomain Code=7 "
false for 'create' @ L6" UserInfo={NSLocalizedDescription=
false for 'create' @ L6}2020-12-10 17:55:48.545592-0500 Pikit[13139:100708] 6.25.0 - [Firebase/Firestore][I-FST000001] Write at posts/f1NriQ2UgIZ9HFOLyhgW7JzjLZw1/userPosts/2020-12-10 22:55:36 +0000 failed: 
false for 'create' @ L6

When I follow the same steps with my production database it runs as expected.当我对我的生产数据库执行相同的步骤时,它会按预期运行。 Here is the code I use to specify the emulator settings:这是我用来指定模拟器设置的代码:

private func emulatorSettings() {
        // [START fs_emulator_connect]
        let settings = Firestore.firestore().settings
        settings.host = "localhost:8080"
        settings.isPersistenceEnabled = false
        settings.isSSLEnabled = false
        Firestore.firestore().settings = settings
        // [END fs_emulator_connect]
    }

I call this function in my viewDidLoad() function of my ViewController like so:我在我的ViewControllerviewDidLoad() function 中这样称呼这个 function:

override func viewDidLoad() {
        super.viewDidLoad()
// called here
        emulatorSettings()
        tableView.reloadData()
        self.reloadInputViews()
        tableView.dataSource = self
        tableView.register(UINib(nibName: K.cellNibName, bundle: nil), forCellReuseIdentifier: K.cellIdentifier)
        if let leftPostArray = userDefaults.array(forKey: fbLeftKey) as? [String]{
            votedLeftPosts = leftPostArray
        }
        if let rightPostArray = userDefaults.array(forKey: fbRightKey) as? [String]{
            votedRightPosts = rightPostArray
        }
        postQuery = Firestore.firestore()
            .collectionGroup("userPosts")
            .order(by: "postTime", descending: false)
            .limit(to: 4)
        
        loadMessages()
    }

I know that this is an old post but I was struggling with the same issue and just fixed it.我知道这是一篇旧帖子,但我一直在努力解决同样的问题,只是修复了它。

I found that I was updating Firestore.firestore().settings too late in my app initialization process.我发现我在我的应用程序初始化过程中更新Firestore.firestore().settings太晚了。 I moved that code to right after calling FirebaseApp.configure() and it worked!我在调用FirebaseApp.configure()之后将该代码移到了右边,它起作用了!

Firestore events are now showing up in my emulator. Firestore 事件现在显示在我的模拟器中。

I found the problem that was preventing me from using the emulated firestore.我发现了阻止我使用模拟 Firestore 的问题。 The emulator does not follow the rules in the production level database but those stored locally in the firestore.rules file.模拟器不遵循生产级数据库中的规则,而是遵循本地存储在 firestore.rules 文件中的规则。 to change the rules I renamed the file to firestore.rules.txt then edited them to allow all reads and writes.为了更改规则,我将文件重命名为 firestore.rules.txt 然后编辑它们以允许所有读取和写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM