2017. 1. 8.

how to send silent push notification in ios by firebase

I am using firebase of google.
I could develop push notification by firebase SDK.  but when I implemented silent-notification(in background state app), I found it is not easy. I googled many pages and I found solution finally.
For another firebase users,  I  am posting on my blog.

* background notification  payload spec.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1

(example)

  1. {
  2. "aps" : {
  3. "content-available" : 1
  4. },
  5. "acme1" : "bar",
  6. "acme2" : 42
  7. }
   - you must add key and value ( "content-available': 1 ) on payload to send data for apns  but problem is that you cannot send that key by firebase-console although you add that-key on custorm-data section. Actually this value  exist outside of 'aps" key.  I found  firebase document, this document says " using . It is not useless in firebase console. 

* using API

I can success by using firebase api 

curl -X POST --header "Authorization: key=<apiauthkey>" \
    --Header "Content-Type: application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d@

## payload.json  file 
{
    "to" : "",
    "priority": "normal",
    "content_available": true,
    "notification" : {
      "body" : "this is message",
      "title" : "notification Title",
      "link": "http://localhost"
    }
}
you can find "content-available:  key.  firebase sever convert  this key to 'content-available:1' 
Below message is  a converted  ''payload" as  "apns"  style ( You can verify in xcode debugging)

   "aps" : {
         "alert": {
                      "title": ...
                      "body": ...
          },
          "content-available": 1
   },
   "gcm.message.link": ...  
}
  # remark , Other fields are not included in 'alert' or 'aps' fields except 'title' and 'body'.  
  you must work more to send to apns  extra datas.
So, you make payload as below to send extra datas.
{
    "to" : "",
    "priority": "normal",
    "content_available": true,
    "notification" : {
      "body" : "this is message",
      "title" : "notification Title"
    },
    "data": {
          "link": ....
     }
}

you must implement code about notification processing code.
( That is not simple also.)

If you find something wrong or others, please comment ~






댓글 없음:

댓글 쓰기