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 QTableWidget重绘程序崩溃
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding