我正在使用Azure推送通知集线器,所有平台的设备都在该集线器上注册。
我的后台是用PHP编写的,看着他们的文档,似乎你需要为每个单独的平台推送一个通知。
$alert = '{"aps":{"alert":"Hello from PHP!"}}';
$notification = new Notification("apple", $alert);
$hub->sendNotification($notification, null);
有没有办法在一次调用中发送到所有平台?
发布于 2018-06-06 05:05:50
你必须为你想要发送到的每个平台创建一个Notification
对象,因为它们使用不同的消息格式:
从您的源链接:
用于iOS的
$alert = '{"aps":{"alert":"Hello from PHP!"}}';
$notification = new Notification("apple", $alert);
$hub->sendNotification($notification, null);
用于Kindle Fire的
$message = '{"data":{"msg":"Hello from PHP!"}}';
$notification = new Notification("adm", $message);
$hub->sendNotification($notification, null);
用于Windows phone8.0和8.1Silverlight的
$toast = '<?xml version="1.0" encoding="utf-8"?>' .
'<wp:Notification xmlns:wp="WPNotification">' .
'<wp:Toast>' .
'<wp:Text1>Hello from PHP!</wp:Text1>' .
'</wp:Toast> ' .
'</wp:Notification>';
$notification = new Notification("windowsphone", $toast);
$notification->headers[] = 'X-WindowsPhone-Target : toast';
$notification->headers[] = 'X-NotificationClass : 2';
$hub->sendNotification($notification, null);
用于安卓的
$message = '{"data":{"msg":"Hello from PHP!"}}';
$notification = new Notification("gcm", $message);
$hub->sendNotification($notification, null);
注意:从2018年4月10日起,Google已弃用GCM。GCM服务端和客户端API已弃用,将于2019年4月11日下架。
从现在开始,你应该为安卓系统使用Firebase Cloud Messaging:https://firebase.google.com/docs/cloud-messaging/
https://stackoverflow.com/questions/50706628
复制相似问题