Firebase 实时数据库在实际构建的 Ionic iOS 上无法运行,但在实时重新加载中可以运行
2022-01-15
612
我遇到了一种有线情况,为此挣扎了一段时间。
我已经使用 Firebase 实时数据库实现了应用内聊天,此解决方案在 Android 的实时重新加载模式和构建模式下均能正常工作,并且在 iOS 的实时重新加载(
ionic cordova run ios -l --external
)模式下也能工作,但在构建应用程序时不起作用。
ionic cordova build ios
我正在相同的设备和相同的代码上测试这个,但在构建模式下失败。
在进行大量调试后,我发现在进行 firebase 数据库调用时控制台中会显示一个错误,但我不确定问题是什么以及它到底在哪里。
[Error] ERROR – Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'BuildInfo.packageName')
attachCallbackListeners@ionic://localhost/vendor.js:116999:39
@ionic://localhost/vendor.js:116900:39
generatorResume@[native code]
asyncGeneratorStep@ionic://localhost/vendor.js:212788:24
_next@ionic://localhost/vendor.js:212810:27
@ionic://localhost/vendor.js:212817:12
ZoneAwarePromise@ionic://localhost/polyfills.js:1419:37
@ionic://localhost/vendor.js:212806:23
generatorResume@[native code]
asyncGeneratorStep@ionic://localhost/vendor.js:212788:24
_next@ionic://localhost/vendor.js:212810:27
run@ionic://localhost/polyfills.js:166:49
@ionic://localhost/polyfills.js:1308:39
runTask@ionic://localhost/polyfills.js:210:57
drainMicroTaskQueue@ionic://localhost/polyfills.js:614:42
invokeTask@ionic://localhost/polyfills.js:523:40
Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'BuildInfo.packageName')
attachCallbackListeners@ionic://localhost/vendor.js:116999:39
@ionic://localhost/vendor.js:116900:39
generatorResume@[native code]
asyncGeneratorStep@ionic://localhost/vendor.js:212788:24
_next@ionic://localhost/vendor.js:212810:27
@ionic://localhost/vendor.js:212817:12
ZoneAwarePromise@ionic://localhost/polyfills.js:1419:37
@ionic://localhost/vendor.js:212806:23
generatorResume@[native code]
asyncGeneratorStep@ionic://localhost/vendor.js:212788:24
_next@ionic://localhost/vendor.js:212810:27
run@ionic://localhost/polyfills.js:166:49
@ionic://localhost/polyfills.js:1308:39
runTask@ionic://localhost/polyfills.js:210:57
drainMicroTaskQueue@ionic://localhost/polyfills.js:614:42
invokeTask@ionic://localhost/polyfills.js:523:40resolvePromise — zone.js:1213resolvePromise — zone.js:1167(anonymous function) — zone.js:1279onInvokeTask — core.js:28659runTask — zone.js:178drainMicroTaskQueue — zone.js:582promiseReactionJob
defaultErrorLogger (vendor.js:54029)
handleError (vendor.js:54077)
next (vendor.js:76833)
next
__tryOrUnsub (vendor.js:207784)
next (vendor.js:207723)
_next (vendor.js:207673)
next (vendor.js:207650)
next (vendor.js:207434)
emit (vendor.js:73485)
run (polyfills.js:166)
onHandleError (vendor.js:76248)
runGuarded (polyfills.js:179)
(anonymous function) (polyfills.js:1106)
drainMicroTaskQueue (polyfills.js:621)
promiseReactionJob
触发对 firebase rdb 的调用的代码
this.db.database.ref(this.messageMetaData.fireBaseString).orderByChild('date')
.on('value', async (resp) => {
this.messageList = snapshotToArray(resp);
await this.iterateImages();
this.loading = false;
if (this.playSound != false) {
this.playChatSound();
}
this.playSound = true;
setTimeout(() => this.content.scrollToBottom(100));
});
我试图添加错误语句,但我没有看到任何其他错误。已看到建议或解决方案,请继续。
使用的插件
" @angular/fire": "^7.0.4",
"firebase": "^9.0.2",
"angularfire2": "^5.4.2",
"firebase-tools": "^7.12.0",
Ionic 信息
Ionic:
Ionic CLI : 6.17.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.9.3
@angular-devkit/build-angular : 12.2.5
@angular-devkit/schematics : 11.2.14
@angular/cli : 12.2.5
@ionic/angular-toolkit : 3.1.1
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : ios 6.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 29 other plugins)
Utility:
cordova-res : not installed globally
native-run (update available: 1.5.0) : 1.4.0
System:
Android SDK Tools : 26.1.1 (/Users/saikiran/Library/Android/sdk)
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v14.18.0 (/usr/local/bin/node)
npm : 6.14.15
OS : macOS Monterey
Xcode : Xcode 13.2.1 Build version 13C100
2个回答
我不是 ionic 的用户,但根据错误提示:
undefined is not an object
您尝试传递
undefined
而不是对象
{
。我猜想
this.messageMetaData.fireBaseString
未定义,或者
resp
未定义。
检查第一个变量,您可以尝试第二个变量:
.on('value', async (resp) => {
if (resp) {
...
}
...
});
FWI:
我认为您需要更新:
"angularfire2": "^5.4.2",
这个包甚至不再有相同的名称。
Jonathan
2022-01-25
最后,当我将 angular 11 更新到 12 时,它奇迹般地起作用了。不确定具体是什么修复了这个问题。–
Sai Kiran
2022-03-25