dongxuying7583 2014-05-14 16:03
浏览 55
已采纳

如何使用命令2发送推送通知二进制格式

There's a related question but is 4 months old and has no answers: PHP Apple iOS Push Notifications: Command2 : Binary Interface and Notification Format

I'm migrating my push notifications from command 0 format to command 2.

I'm using apple docs https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html and I can't find what im doing wrong. Im using php by the way.

for commmand 0: (it works)

$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

for command 1: (it works)

$msg =
  chr(1)
. chr(1).chr(1).chr(1).chr(1) //id 1111
. pack('N', time() + 86400) //tomorrow expiration date
. pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

for command 2: (doesn't work)

$msgInner =
  chr(1)
. pack('n', 32)
. pack('H*', $deviceToken)

. chr(2)
. pack('n', strlen($payload))
. $payload

. chr(3)
. pack('n', 4)
. chr(1).chr(1).chr(1).chr(1)

. chr(4)
. pack('n', 4)
. pack('N', time() + 86400)

. chr(5)
. pack('n', 1)
. chr(10);

$msg=
chr(2)
. pack('n', strlen($msgInner))
. $msgInner;

the notification doesn't arrive neither the command 8 response packet

  • 写回答

1条回答 默认 最新

  • doulan1866 2014-05-14 16:34
    关注

    Seems I was using a 2 byte frame size instead of 4 byte

    $msg=
    chr(2)
    . pack('N', strlen($msgInner)) //N is for 32 bits big endian
    . $msgInner;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题