dongxuying7583
dongxuying7583
2014-05-14 16:03

如何使用命令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 doulan1866 7年前

    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;
    
    点赞 评论 复制链接分享