首页 > 解决方案 > 为什么我的 iOS 应用程序没有写入 Firestore 模拟器

问题描述

我正在尝试设置一个 firebase 模拟器来模拟我的 iOS 应用程序中的一些操作。当我尝试向我的模拟 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

当我对我的生产数据库执行相同的步骤时,它会按预期运行。这是我用来指定模拟器设置的代码:

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]
    }

我在我viewDidLoad()的函数中调用这个函数ViewController

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()
    }

标签: iosswiftfirebasegoogle-cloud-firestore

解决方案


我发现了阻止我使用模拟 Firestore 的问题。模拟器不遵循生产级数据库中的规则,而是遵循本地存储在 firestore.rules 文件中的规则。为了更改规则,我将文件重命名为 firestore.rules.txt 然后编辑它们以允许所有读取和写入。


推荐阅读