firebase subscribeToTopic error
See original GitHub issueI’m not able to subscribe to a topic, below my app.ts excerpt
import "./bundle-config";
import * as app from 'application';
import * as firebase from "nativescript-plugin-firebase";
firebase.init({
onMessageReceivedCallback: (message: firebase.Message) => {
console.log(`Title: ${message.title}`);
console.log(`Body: ${message.body}`);
// if your server passed a custom property called 'foo', then do this:
console.log(`value of 'foo': ${message.data.foo}`);
}
}).then(
instance => {
console.log(`firebase.init done !! [${instance}]`);
firebase.subscribeToTopic("/topics/musa-news").then(
(value) => console.log("sub ok:", value),
(reason) => console.log("sub err:", reason)
);
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
In the console I got:
JS: sub err: Can be run only after init
Probably I don’t understand when it is safe to call subscribeToTopic, the message says after init but apparently the init then() context is not such place.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Trying to subscribe to topic on Firebase Cloud Messaging ...
When i try to subscribe to a topic i get the following error: .subscribeToTopic is not a function. const messaging = firebase.messaging(); ...
Read more >Topic messaging on Android - Firebase - Google
If you provide an array with over 1,000 registration tokens, the request will fail with a messaging/invalid-argument error. The subscribeToTopic() and ...
Read more >Cloud Messaging | React Native Firebase
Subscribing to topics. To subscribe a device, call the subscribeToTopic method with the topic name (must not include "/"):.
Read more >Cloud Messaging | FlutterFire
Before using Firebase Cloud Messaging, you must first have ensured you have ... To subscribe a device, call the subscribeToTopic method with the...
Read more >FCM, send to topic and "Not Registered" error - Google Groups
to Firebase Google Group. Hello there, I developed an Android app that subscribes to a topic ( subscribeToTopic() ) and then receives notifications...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me, file was firebase.nativescript.json located at the root folder of project and editing it didn’t work.
How I fixed it:
You can check if firebase instance exists with:
I had the same problem, I did some research and I found out that “firebase.instance” is null and that was caused by “com.google.firebase.database” being undefined.
How i fixed it I edited the nativescript.firebase.json and set “realtimedb” to true, after that it worked!