FCM是否支持iOS 13的新apns-push-type [英] Does FCM support the new apns-push-type for iOS 13

查看:194
本文介绍了FCM是否支持iOS 13的新apns-push-type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前有一个解决方案,可以将推送通知从FCM发送到APNS,然后再发送到iOS.由于iOS13的引入,APNS现在在任何传入负载中都要求apns-push-type,以指定它是警报通知,背景通知还是任何其他类型.我想知道如何在发送到FCM的消息中添加此信息.

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.

当前,我们使用pyFCM将消息发送到FCM.并且,我们遵循此页面作为参考: https://firebase.google. com/docs/cloud-messaging/http-server-ref

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,
                                       )

这与现有的iOS应用程序兼容.但是对于iOS 13,我找不到任何指定apns-push-type的位置,也找不到FCM将转换为要发送到APNS的apns-push-type的任何等效字段.

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.

我知道iOS 13相对较新,因此每个人仍在努力调整现有解决方案以适应它.希望有人能给我一些见识,以了解如何将apns-push-type放入我现有的解决方案中.谢谢.

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.

推荐答案

我们的解决方案是根据请求将其添加到标头中(此答案在PHP代码上)

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);

这篇关于FCM是否支持iOS 13的新apns-push-type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆