Exprove
Exprove

Reputation: 1421

How to debug iOS not receiving push notifications (Flutter using firebase_messaging)?

Currently, I am using flutter firebase_messaging library to be able to push notifications for iOS and Android.

I am having problems on receiving notifications on iOS either sent by firebase console (notification test by specifying an apnsToken) or by a curl request using the legacy HTTP Protocol (only notification, no iOS or Android payload sent). On Android both methods work fine and the notifications are received.

I have followed all the specified steps on the documentation without success:

More info: I can get APNs IDs on both iOS and Android, so I guess the problem is not in firebase (core) configuration but maybe on firebase messaging. However, the iOS APN (only caps lock characters and numbers) seems really different from a Android APN. Is it normal?

I did not mess with FirebaseAppDelegateProxyEnabled, even thought I receive the following message: FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers.

I know that the curl request returns 200 OK (response code and I am receiving the notification on Android).

Any step that I am forgetting? How can I debug this?

Upvotes: 4

Views: 3025

Answers (1)

fravolt
fravolt

Reputation: 3001

Debugging this in general is quite difficult in my experience. I had a similar issue, which I discovered was due to two mistakes I made. While you've probably resolved your issues already, I'll post this here so other people might benefit from it.

1. Request permissions

On iOS, you need to request permissions to send notifications, otherwise they'll never arrive. Take a look at the documentation for the specific command. In my case, it worked by doing

FirebaseMessaging.instance.requestPermission(
  alert: true,
  announcement: false,
  badge: true,
  carPlay: false,
  criticalAlert: false,
  provisional: false,
  sound: true,
);

2. Use the normal token, not the APNs token

This should have been obvious, but I somehow managed to think that if Platform.isIOS, I need to use the APNs token. This is not true of course, you should always just use

String? token = await FirebaseMessaging.instance.getToken();

to retrieve it.

Upvotes: 2

Related Questions