如何将静默通知从服务器发送到ios设备



这是我的python脚本,它将fcm通知发送到设备。

它发送优先级通知而不是静默通知。我怎样才能让他们沉默?

def sendGCMToTopiciOS():
    url = 'https://fcm.googleapis.com/fcm/send'
    headers = {
        'UserAgent': "GCM-Server",
        'Content-Type': 'application/json',
        'Authorization': 'key=' + 'XXXXXXXXXXXXXXXXXXXX',
    }
    data = {'title': 'Yugam', 'message': 'Hello Everyone', 'event': '13', 'workshop': '-1',
            'link': 'https://www.google.com'}
    notification = {
        'body': data.get('message'),
        'title': data.get('title')
    }
    values = {
        'to': '/topics/' + 'global',
        'data': data,
        'notification': notification,
         "aps":{
             "content-available":1}
    }
    pipe = requests.post(url=url, json=values, headers=headers)
    return pipe.json()

要发送数据消息,您需要跳过 json 有效负载的notification部分

"通知"字段将导致iOS 10将您的通知发送到系统,并根据给定的值自动显示通知。如果您正在寻找完全静默的通知,请尝试:

values = {
    'to': '/topics/' + 'global',
    'content_available': true
    'priority': 'high',
    'data': data
}

这将在后台传递,没有警报。"content_available"字段也将转换为"内容可用":1 通过 APNS 的 GCM 服务器。

最新更新