2

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

TomPl
  • 21
  • 4
  • Please don't include `FCM_SERVER_KEY` in an app you ship to your clients. Doing so allows anyone who gets access to it to take the key, and use it to send whatever message they want to all your users. As its name implies, the key should only be used on servers or otherwise trusted environments. For more on this, see https://stackoverflow.com/questions/37990140/how-to-send-one-to-one-message-using-firebase-messaging/37993724#37993724 – Frank van Puffelen Dec 26 '20 at 01:46
  • True, but this is just a student project, and I don't really have a server, just the database nad FCM... And even if I had a server - wouldn't I still have to store some identification token on device to be able to communicate with the server? – TomPl Dec 26 '20 at 22:29

1 Answers1

0

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

NinjaDeveloper
  • 1,620
  • 3
  • 19
  • 51
  • Yes, I am registered developer and I have registered push notifications for my app....I feel like I have really tried everything – TomPl Dec 26 '20 at 22:45
  • Follow the link step by step. I had same problem last year I managed to make it work as mock – NinjaDeveloper Dec 28 '20 at 08:44