I have a list of push tokens tokens (about 10k) for my application, and I do not track the status of active / remote tokens. When a new user is added to the system, he is added with his token
(on one device, one release notification token can be stored, in case of a change in the token - there wasn’t any application life cycle for the last 6 months), it is modified with a new token)
To send push notifications for one user, I use the following PHP script
<?php // connecting to sql sql_connect(); // get user token from sql $token = sql_gettoken(); // Put your device token here (without spaces): $deviceToken = $token; // Put your private key passphrase here: $passphrase = 'my_passphrase'; // Put your alert message here: if ($_GET["message"]) $message = $_GET["message"]; else $message = 'This is a default message in case no message is defined'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'production_cerfiticate.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream_socket_client( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL); echo 'Connected to APNS' . PHP_EOL; // Create the payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default' ); // Encode the payload as JSON $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered' . PHP_EOL; // Close the connection to the server fclose($fp); ?>
I believe that if I support $ fp (connecting to the APNS server), I can send several push notifications between them (am I not sure about this?). But I read that if the token is in a stand-alone / remote application, the connection is closed by the side on the apple side, which means that the call notification cycle will not succeed.
Any tips on converting this unidirectional notification script to a broadcast notification? I am not advised to check this, since the first test will be live broadcast, and I only have 1 shot for that.
EDIT: I missed the most important part . If I simply switch to this php script in a loop for all device tokens, which means that he will try to call it for remote applications and assets, will Apple block / deactivate / deny my certificate or my ability to send push notifications?
- For others looking for broadcast, it seems like Apple has no restrictions on push notifications.
Greetings