0

I'm implementing angularfire but it's also a generic question.

I use RealTime Database and FCM modules. But, I don't need to show browser or background notifications, I'm just only communicating server with client sending push messages (for refreshing purposes only).

This current code is requesting user permissions on the browser. It's possible to avoid this?

this.afMessaging.requestToken
  .subscribe(
    token => {
      console.log('Permission granted! Save to the server!', token);
      this.updateFirebaseToken(token);
      this.updateAPIToken(token);
      },
    err => { console.log('Unable to get permission to notify.', err); }
  );
ivanros92
  • 1
  • 1

1 Answers1

0

Yes, it is mandatory to ask for permission, even if you don't intend to show the user a notification. There's been an even-more-recent question here asking the same basic thing that has a couple good answers explaining why by people way smarter and more experienced than me.

In case anyone can't access that question in the future, I'll include Google Dev Adocate Doug Stevenson's excellent concise explanation here of why it's required:

It's to protect the user's preferences about what your app is allowed to do. The way push messaging works on browsers is by using a service worker. Even though you say you don't need a service worker, you are actually making using of it when using Firebase Cloud Messaging in your app.

Given that, the prompt is necessary because the browser doesn't know what you intend to do with that push message. If the user doesn't trust your app, they should have the right to limit what it can actually do, especially when they're not using your app. Mobile operating systems (iOS, Android) are the same way.

JeremyW
  • 5,157
  • 6
  • 29
  • 30