Can't send remote notifications to iOS using POST request to Firebase Cloud Messaging

Viewed 204

TL;DR: React native app, sending remote push notifications works for Android, not for iOS.

Hi, I am developing react-native app and trying to send notification to other users after a user makes a specific action. I have no backend, just Firestore and Firebase Cloud Messaging.

For android it works just by sending a POST request from the app like this:


export const sendPushNotification = async (recipientToken, title, body) => {
  const FCM_SERVER_KEY =
    'AAAA6dAudaoXXXXXXX...XXXXXXXXXwbBaKNh';
  const message = {
    to: recipientToken,
    notification: {
      title: title,
      body: body,
      vibrate: 1,
      sound: "default",
      show_in_foreground: true,
      priority: 'high',
      content_available: true,
    },
    data:{
      title: title,
      message: body
    }
  };

  let headers = new Headers({
    'Content-Type': 'application/json',
    Authorization: 'key=' + FCM_SERVER_KEY,
  });

/************* this is where the message is sent *********************/
  let response = await fetch('https://fcm.googleapis.com/fcm/send', {
    method: 'POST',
    headers,
    body: JSON.stringify(message),
  });
};

But for iOS it does not work (even though I have requested notifications permissions). Also it is really hard to test, since I can't send push notification to an emulated iPhone, so I need to release new version after each change.

Any thoughts about this?

Thanks

Edit: Here are picture of my projects capabilities in Xcode and my certificates for notifications on Apple Developer website: Here is a picture of my projects capabilities in Xcode:

These are my certificates for notifications

1 Answers

did you register your app with the Apple Push Notification service (APNs) if not read this article iOS remote push notifications in a nutshell? and you have to be an apple register developer to access the Apple Push Notification service.

I think you can test the Push Notification iOS simulator use this app Push Notification Tester to send the Notification

Related