Does FCM support the new apns-push-type for iOS 13

孤街浪徒 提交于 2020-01-24 12:09:10

问题


We currently have a solution to send the push notification from FCM to APNS and then to iOS. Due to the introduction of iOS13, the APNS now requires apns-push-type in any incoming payload that specifies whether it's an alert notification, background notification, or any other type. I am wondering how to add this information in the message sent to the FCM.

Currently we use pyFCM to send messages to FCM. And we follow this page as reference: https://firebase.google.com/docs/cloud-messaging/http-server-ref

from pyfcm import FCMNotification
push_service = FCMNotification(api_key="XXXX")
registration_id = '<Token>'
data_message = {
    "Score": "3*1",
    "DeviceId": "XXXXXX",
}

# Background notification
result = push_service.notify_single_device(registration_id=registration_id,
                                       content_available=True,
                                       data_message=data_message)

# Alert notification
result = push_service.notify_single_device(registration_id=registration_id,
                                       message_title='Sample title',
                                       message_body='Sample body',
                                       data_message=data_message,
                                       )

This works fine with existing iOS app. But for iOS 13, I cannot find any place to specify apns-push-type, or any equivalent field that FCM will translate to apns-push-type that would be sent to APNS.

I know iOS 13 is relatively new, so everyone is still working on adapting the existing solution to it. Hopefully someone can give me some insight how to put the apns-push-type into my existing solution. Thanks.


回答1:


Just add 'apns-push-type' = 'XXX' in the request header which you want to send to FCM




回答2:


you can add this option using 'extra_kwargs' of the Notification.

Add extra_kwargs={"apns_push_type":"background"} for background notification.

# Background notification 
result = push_service.notify_single_device(registration_id=registration_id,
                                           content_available=True,
                                           data_message=data_message,
                                           low_priority=True,
                                           extra_kwargs={"apns_push_type": "background"})

Also, mark the priority of background notification as low. This is done by sending low_priority as true.

For alert notifications, we are required to send the apns push-type as "alert"

 # Alert notification
result = push_service.notify_single_device(registration_id=registration_id,
                                   message_title='Sample title',
                                   message_body='Sample body',
                                   data_message=data_message,
                                   extra_kwargs={"apns_push_type": "alert"}
                                   )



回答3:


you can check if push notifications work json api post request to https://fcm.googleapis.com/fcm/send url. in configure header Content-Type : application/json and Authorization:key=<Your FCm server key>

then in request body add these

{ "to" : "device_token",
 "notification" : 
 { 
    "title": "message title!", 
     "body": "MESSAGE BODY",

 "token": "XXXXXXXXXX", 
 "id": 1959,
      "sound": "default"
                                      },

 "apns": {
    "headers": { 
      "apns-push-type": "alert"
    }

  }
}

then you can check if it works or not. my project was previously working before updating IOS 13. after update, notifications doesnt worked on background, adding

"apns": {
    "headers": { 
      "apns-push-type": "alert"
    }

  }

to project made receive notifications possible




回答4:


Our solution is to add it to the header upon request (This answer is on PHP code)

$headers = [
            'Authorization: key=' . $serverKey,
            'Content-Type: application/json',
            'apns-push-type: background'
          ];

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $fcmEndpoint); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CURL_IPRESOLVE_V4); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payloads)); 
$result = json_decode(curl_exec($ch), true); curl_close($ch);


来源:https://stackoverflow.com/questions/58194041/does-fcm-support-the-new-apns-push-type-for-ios-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!