Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send actionable notifications to iOS with FireBase?

We are currently evaluating Firebase as a future push notification service. Is there a way to send actionable notifications to iOS devices? At the moment we use parse to send pushes, we set the "category" parameter in the payload and the additional actions on the notifications are working. We tried to set this parameter in the firebase console or via the firebase rest api, but the notification actions are not working, it seems the payload is somehow different then iOS expects.

like image 735
simsimmal Avatar asked Aug 25 '16 06:08

simsimmal


People also ask

How do I get push notifications on iOS?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.

Can I use Firebase for push notification to iOS?

For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Can you send push notifications with Firebase?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

How to configure push notifications on Firebase for iOS?

Configure push notification Go to Firebase Console -> Settings -> Project Settings -> Cloud Messaging -> iOS app configuration If you use certificate, use just 1 Apple Push Notification service SSL for both fields If you use Authenticate Key, fill in APNS auth key

What is Firebase Cloud Messaging?

Concisely put, Firebase Cloud Messaging—or FCM for short—is a cross-platform cloud messaging and notification solution from Google, enabling developers to send push notifications to their app's end users through the Firebase Notification Composer, or a Firebase-exposed set of APIs.

How do I add firebase to my iOS app?

Enter the following to build the pods: Open up the workspace Firebase-FCM.xcworkspace, and in a browser, go to the Firebase panel and create a new project: Next, click on Add Firebase to your iOS app, which walks you step by step through the process of registering your app on Firebase.

How do I set up push notifications on iOS devices?

The “iOS App ID Settings” page will show up. Scroll all the way down until you see “Push Notifications.” It is time for us to create a “Client SSL Certificate.” This will allow our notification server (Firebase) to connect to the Apple Push Notification Service.


2 Answers

Thanks Malik for the answer. FCM seems to translate the android specific "click_action" property to the iOS specific "category" property.

We send firebase push notifications via their REST API, which can be easily used for testing with postman.

Here is the REST version:

POST https://fcm.googleapis.com/fcm/send

Headers:

  • Authorization: key=YOUR_FIREBASE_SERVER_KEY
  • Content-Type: application/json

Body:

{ "notification": {
    "text": "YOUR_PUSH_TEXT",
    "click_action":"YOUR_IOS_ACTIONABLE_NOTIFICATION_CATEGORY"
  },
  "to" : "YOUR_PUSH_TOKEN",
  "data": {
    "YOUR_CUSTOM_DATA": "DATA"
  }
}
like image 92
simsimmal Avatar answered Nov 15 '22 13:11

simsimmal


Currently categories not supported in FCM console but still if you want to test you can use curl post call and test. You can add category to your payload from your server and use FCM api to push notification to iOS.

curl --header "Authorization: key=<YOUR_SERVER_KEY>" --header Content-  Type:"application/json" https://fcm.googleapis.com/fcm/send  -d "{\"to\":\"Device Token\",\"priority\":\"high\",\"notification\": {\"title\": \"Shift Alert\",\"text\": \"Would you like to accept  shift today 11:30 to 13:30  \",\"click_action\":\"INVITE_CATEGORY\"}}"

Authorization: key=YOUR_SERVER_KEY Make sure this is the server key, whose value is available in your Firebase project console under Project Settings > Cloud Messaging. Android, iOS, and browser keys are rejected by FCM.

INVITE_CATEGORY = Your category you using in your code

below is response dictionary you will get on action tap:

{
aps =     {
    alert =         {
        body = "Would you like to accept shift today 11:30 to 13:30  ";
        title = "Shift Alert";
    };
    category = "INVITE_CATEGORY";
};
"gcm.message_id" = "0:12233487r927r923r7329";
}
like image 45
Malik Avatar answered Nov 15 '22 12:11

Malik