Native implementation not called if imports done in Capacitor v3 style
See original GitHub issueDescribe the bug When I use the Capacitor v3 style of imports and run it as iOS app, not the native implementation but the web implementation is called.
To Reproduce Import the plugin and use it like
import { FirebaseAnalytics } from "@capacitor-community/firebase-analytics";
FirebaseAnalytics.logEvent({
name: "select_content",
params: {
content_type: "image",
content_id: "P12453",
items: [{ name: "Kittens" }],
},
});
Then I get the error message: Firebase analytics is not initialized. Make sure initializeFirebase() is called once
Additionally, I debugged a bit in Xcode and see that the plugin is registered(CapacitorBridge.registerPlugin()
successfully and also exported via JSExport.exportJS()
.
If I use the “old” style, everything works fine, even when using the same capacitor version; it is marked as deprecated though:
import "@capacitor-community/firebase-analytics";
import { Plugins } from '@capacitor/core';
const {FirebaseAnalytics} = Plugins;
FirebaseAnalytics.logEvent({
name: "select_content",
params: {
content_type: "image",
content_id: "P12453",
items: [{ name: "Kittens" }],
},
});
Unfortunately, I didn’t find any clue what’s going wrong.
Expected behavior The native implementation should be called, also when using the Capacitor v3 style imports.
Smartphone (please complete the following information):
- Device: iPhone6s, Xcode Simulator
- OS: iOS 14.7.1, iOS 15
- Browser: Ionic WkWebview
Additional context For other plugins like @capacitor/share the new style imports are working just fine.
Versions used:
"@capacitor-community/firebase-analytics": "^0.3.3",
"@capacitor/core": "3.2.3",
"@capacitor/ios": "3.2.3",
"@capacitor/share": "^1.0.4",
"@ionic/react": "^5.5.0",
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
For those of you having issues, I was able to solve it by ensuring the FirebaseAnalytics calls are async.
@bellispmo I had to downgrade to
"@capacitor-community/firebase-analytics": "^0.3.3"
and import it like thatuntil they fix this. I hope this will help.