views:

805

answers:

3

HI All,

Has anybody been able to extract the device tokens from the binary data that iPhone APNS feedback service returns using PHP? I am looking for something similar to what is been implementented using python here http://www.google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#m5eOMDWiKUs/APNSWrapper/%5F%5Finit%5F%5F.py&q=feedback.push.apple.com

As per the Apple documentation, I know that the first 4 bytes are timestamp, next 2 bytes is the length of the token and rest of the bytes are the actual token in binary format. (http://developer.apple.com/IPhone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple%5Fref/doc/uid/TP40008194-CH101-SW3)

I am successfully able to extract the timestamp from the data feedback service returns, but the device token that I get after i convert to hexadecimal using the PHP's built in method bin2hex() is actually different than original device token. I am doing something silly in the conversion. Can anybody help me out if they have already implemented APNS feedback service using PHP?

TIA, -Anish

A: 

The best place to go for this is actually the Apple developer forums in internal to the iPhone portal - the have a bunch of examples in different languages for working with these push requests.

I'm also currently at an 360iDev push session, and they noted an open source PHP server can be found at:

http://code.google.com/p/php-apns/

Kendall Helmstetter Gelner
I had checked this php-apns project earlier. It doesnt talk of feedback service :-( Any other pointers is much appreciated.Thanks,-Anish
Anish
A: 

Once you have your binary stream, you can process it like this:

while ($data = fread($stream, 38)) {
  $feedback = unpack("N1timestamp/n1length/H*devtoken", $data);
  // Do something
}

$feedback will be an associative array containing elements "timestamp", "length" and "devtoken".

Chris Newman