Firebase 实时数据库在实际构建中无法在 Ionic iOS 上运行,但可以在实时重新加载中运行

Sai*_*ran 5 javascript cordova firebase ionic-framework firebase-realtime-database

我有一个有线情况,为此苦苦挣扎了一段时间。

\n

我已经使用 Firebase 实时数据库实现了 inApp 聊天,该解决方案在 Android 中的实时重新加载模式和构建模式下都可以正常工作,并且ionic cordova run ios -l --external在 iOS 中的实时重新加载 ( ) 模式下也可以正常工作,但在构建应用程序时不起作用。ionic cordova build ios

\n

我正在相同的设备和相同的代码上对此进行测试,但在构建模式下失败。

\n

在进行大量调试时,我发现在进行 Firebase 数据库调用时控制台中显示一个错误,但我不确定问题是什么以及到底在哪里。

\n
[Error] ERROR \xe2\x80\x93 Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'BuildInfo.packageName')\nattachCallbackListeners@ionic://localhost/vendor.js:116999:39\n@ionic://localhost/vendor.js:116900:39\ngeneratorResume@[native code]\nasyncGeneratorStep@ionic://localhost/vendor.js:212788:24\n_next@ionic://localhost/vendor.js:212810:27\n@ionic://localhost/vendor.js:212817:12\nZoneAwarePromise@ionic://localhost/polyfills.js:1419:37\n@ionic://localhost/vendor.js:212806:23\ngeneratorResume@[native code]\nasyncGeneratorStep@ionic://localhost/vendor.js:212788:24\n_next@ionic://localhost/vendor.js:212810:27\nrun@ionic://localhost/polyfills.js:166:49\n@ionic://localhost/polyfills.js:1308:39\nrunTask@ionic://localhost/polyfills.js:210:57\ndrainMicroTaskQueue@ionic://localhost/polyfills.js:614:42\ninvokeTask@ionic://localhost/polyfills.js:523:40\nError: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'BuildInfo.packageName')\nattachCallbackListeners@ionic://localhost/vendor.js:116999:39\n@ionic://localhost/vendor.js:116900:39\ngeneratorResume@[native code]\nasyncGeneratorStep@ionic://localhost/vendor.js:212788:24\n_next@ionic://localhost/vendor.js:212810:27\n@ionic://localhost/vendor.js:212817:12\nZoneAwarePromise@ionic://localhost/polyfills.js:1419:37\n@ionic://localhost/vendor.js:212806:23\ngeneratorResume@[native code]\nasyncGeneratorStep@ionic://localhost/vendor.js:212788:24\n_next@ionic://localhost/vendor.js:212810:27\nrun@ionic://localhost/polyfills.js:166:49\n@ionic://localhost/polyfills.js:1308:39\nrunTask@ionic://localhost/polyfills.js:210:57\ndrainMicroTaskQueue@ionic://localhost/polyfills.js:614:42\ninvokeTask@ionic://localhost/polyfills.js:523:40resolvePromise \xe2\x80\x94 zone.js:1213resolvePromise \xe2\x80\x94 zone.js:1167(anonymous function) \xe2\x80\x94 zone.js:1279onInvokeTask \xe2\x80\x94 core.js:28659runTask \xe2\x80\x94 zone.js:178drainMicroTaskQueue \xe2\x80\x94 zone.js:582promiseReactionJob\n    defaultErrorLogger (vendor.js:54029)\n    handleError (vendor.js:54077)\n    next (vendor.js:76833)\n    next\n    __tryOrUnsub (vendor.js:207784)\n    next (vendor.js:207723)\n    _next (vendor.js:207673)\n    next (vendor.js:207650)\n    next (vendor.js:207434)\n    emit (vendor.js:73485)\n    run (polyfills.js:166)\n    onHandleError (vendor.js:76248)\n    runGuarded (polyfills.js:179)\n    (anonymous function) (polyfills.js:1106)\n    drainMicroTaskQueue (polyfills.js:621)\n    promiseReactionJob\n
Run Code Online (Sandbox Code Playgroud)\n

触发调用 firebase rdb 的代码

\n
  this.db.database.ref(this.messageMetaData.fireBaseString).orderByChild('date')\n      .on('value', async (resp) => {\n        this.messageList = snapshotToArray(resp);\n        await this.iterateImages();\n        this.loading = false; \n        if (this.playSound != false) {\n          this.playChatSound();\n        }\n        this.playSound = true;\n        setTimeout(() => this.content.scrollToBottom(100));\n      });\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试添加错误语句,但没有看到任何其他错误。看到了继续的建议或解决方案。

\n

使用的插件

\n
"       @angular/fire": "^7.0.4",\n        "firebase": "^9.0.2",\n        "angularfire2": "^5.4.2",\n        "firebase-tools": "^7.12.0",\n\n
Run Code Online (Sandbox Code Playgroud)\n

离子信息

\n
Ionic:\n\n   Ionic CLI                     : 6.17.0 (/usr/local/lib/node_modules/@ionic/cli)\n   Ionic Framework               : @ionic/angular 5.9.3\n   @angular-devkit/build-angular : 12.2.5\n   @angular-devkit/schematics    : 11.2.14\n   @angular/cli                  : 12.2.5\n   @ionic/angular-toolkit        : 3.1.1\n\nCordova:\n\n   Cordova CLI       : 10.0.0\n   Cordova Platforms : ios 6.1.1\n   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 29 other plugins)\n\nUtility:\n\n   cordova-res                          : not installed globally\n   native-run (update available: 1.5.0) : 1.4.0\n\nSystem:\n\n   Android SDK Tools : 26.1.1 (/Users/saikiran/Library/Android/sdk)\n   ios-deploy        : 1.11.4\n   ios-sim           : 8.0.2\n   NodeJS            : v14.18.0 (/usr/local/bin/node)\n   npm               : 6.14.15\n   OS                : macOS Monterey\n   Xcode             : Xcode 13.2.1 Build version 13C100\n
Run Code Online (Sandbox Code Playgroud)\n

Jon*_*han 0

我不是离子人,但根据错误:

undefined is not an object 
Run Code Online (Sandbox Code Playgroud)

你试图传递undefined而不是一个 object {}。我想要么this.messageMetaData.fireBaseString是未定义的,要么resp是未定义的。

检查第一个变量,你可以尝试第二个变量:

undefined is not an object 
Run Code Online (Sandbox Code Playgroud)

FWI:

我认为你需要更新:

.on('value', async (resp) => {
  if (resp) {
    ...
  }
  ...
});
Run Code Online (Sandbox Code Playgroud)

这个包甚至不再具有相同的名称。