ios - 为什么我的 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()
}
解决方案
我发现了阻止我使用模拟 Firestore 的问题。模拟器不遵循生产级数据库中的规则,而是遵循本地存储在 firestore.rules 文件中的规则。为了更改规则,我将文件重命名为 firestore.rules.txt 然后编辑它们以允许所有读取和写入。
推荐阅读
- c++ - GNUMakefile 中 INCS 、 LIBS 和 OBJS 的可选包含,制作版本 3.82
- javascript - 实现了具有意外价值的 AES 256
- react-native - 使用react hook表单时如何更改检查规则的顺序?
- user-interface - 如何找到用于 UI 自定义的 jsp 文件
- android - ReviewManager Api 使用什么来代替 TaskException?
- php - LaravelExcel:找不到接口“App\Exports\FormView”
- jupyter-notebook - AttributeError:模块“torchvision”没有属性“__version__”
- angular - 在运行时禁用注册(Angular + NestJS)
- flutter - Flutter 中的后台进程
- azure - 如何获取 Azure Active Directory Graph(不是 Microsoft Graph)的服务主体?