I am trying to integrate fcm in my angular 6.
Here is what i have done.
firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '93480234033'
});
const messaging = firebase.messaging();
push-notification.js
import firebase from 'firebase';
export const askForPermissioToReceiveNotifications = async () => {
try {
const messaging = firebase.messaging();
console.log('000ooppp', messaging)
messaging.requestPermission()
.then(function(){
console.log('I am in here');
return messaging.getToken()
.then(function(currentToken) {
console.log(currentToken);
})
}).catch(function(err) {
console.log('Unable to get permission to notify.', err);
});
} catch (error) {
console.error(error);
}
}
these two files are in src folder.
i have created an app on firebase console and i have got the config object
config: {
apiKey: "*****",
authDomain: "*****",
databaseURL: "*****",
projectId: "*****",
storageBucket: "*****",
messagingSenderId: "*****"
}
And in my app.module.ts file i am initialising firebase with the above object
import { AngularFireModule } from 'angularfire2';
import { ServiceWorkerModule } from '@angular/service-worker';
and then in import
imports: [
...
...
AngularFireModule.initializeApp(environment.firebase),
ServiceWorkerModule.register('/combined-worker.js', { enabled: environment.production })
...
...
]
and in app.component.ts
import { askForPermissioToReceiveNotifications } from './../push-notification';
ngOnInit () {
console.log('pop')
askForPermissioToReceiveNotifications();
}
what i want to do is when user lands on the page and he allows notification to be shown to him, a unique device token id should be generated for that particular user, how can i generate device token id when he clicks on show notification?
getting this error in console
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app)