1

I'm having an issue with Firebase Cloud Messaging in my Flutter app where:

  • On iOS: Messages only work when sent via Firebase Console, but not when sent from my backend
  • On Android: Messages work perfectly from both Firebase Console and backend
  • I'm using the firebase_messaging package 15.2.5 and firebase core 3.13.0

Key Additional Information:

  • My app subscribes users to a topic (using their user ID) when they login
  • The backend sends notifications to these user-specific topics
  • Topic subscription appears to work (no errors), but messages never arrive on iOS

What I've Tried:

. Verified APNs certificates are properly configured in Firebase Console . Ensured the payload structure matches what iOS expects . Confirmed the device token is being correctly registered . Checked that background modes are enabled in Xcode . Verified notification permissions are granted

Topic subscription in Flutter:

// Called during user login
subscribeToNotification(String userId) async {
 try {
   await FirebaseMessaging.instance.subscribeToTopic(userId);
 } catch (e) {
   print('Subscription error ${e.toString()}');
 }
}

Backend sending code (TypeScript):

const sendDataNotif = async (token: string, data: object, topic: string) => {
  try {
    const headers = {
      Authorization: 'Bearer ' + token,
    };
    const payload = {
      message: {
        topic,
        data,
      },
    };
 
    return await axios({
      method: 'post',
      url: `https://fcm.googleapis.com/v1/projects/${key.project_id}/messages:send`,
      data: payload,
      headers,
    });
  } catch (error: any) {
    console.log(error.message);
  }
};
0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.