0

My last app get a lot of user (> 200 000), i have set my own push solution.

Nevertheless i'm facing new problems and when i want to push all my user the same time.

After opened a ssl connexion i make a loop with all token and using if the token is valid (isDigit and length > 64 ) but what i have understood is that one of the token is no more valid regarding my apns .pem apns will stop the loop. I know i need to call the feedback service to get my invalid token but i push my user for the first the apns will stop my loop and i can't get any feedback service !

I have set a simple php script to get feedback :

<?php 

$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', 'myApns.pem');
$apns = stream_socket_client('ssl://feedback.push.apple.com:2196',
    $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);

if(!$apns) {
    echo "ERROR $errcode: $errstr\n";
    return;
}

$feedback_tokens = array();
//and read the data on the connection:
while(!feof($apns)) {
    $data = fread($apns, 38);
    if(strlen($data)) {
        $feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
    }
}
fclose($apns);
print_r($feedback_tokens);
echo("done");

?>

But it always print me a null array (Array()). Is there any solution in php so i send my token to the apns which verify the token is valid or not?

Wolfram
  • 8,044
  • 3
  • 45
  • 66
user2434385
  • 281
  • 1
  • 3
  • 16
  • 1
    Are you trying this on AdHoc mode or developer mode ? [Check this](http://stackoverflow.com/questions/2246187/testing-apple-push-notifications-feedback-no-items-received), it says it only works with AdHoc/Live mode – Janak Nirmal Jan 17 '14 at 11:27
  • i'm on production mode, thanks. – user2434385 Jan 17 '14 at 11:48

1 Answers1

0

Restrict null value before loop is calling.

And try these code

    $passphrase = PASSWORD;
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'MyApns.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

    // Open a connection to the APNS server
    $fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

    if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

    $body['aps'] = array('alert' => $msg,'sound' => 'default');
    $payload = json_encode($body);
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result){
        return false;
        //echo 'Message not delivered' . PHP_EOL;
    }else{
        return true;
        //echo 'Message successfully delivered' . PHP_EOL;
}fclose($fp);
}
शु-Bham
  • 952
  • 1
  • 7
  • 14
  • thank you man but it does not give me feedback, your code simple push a user, the apns will write the token even if it unvalid (the user delete the app) but if one is not valid it won't take of care of next token. but thank you very much. – user2434385 Jan 17 '14 at 11:07