I am sending push notifications to iPhone devices. About 2500 devices are stored in my database tables. But only 270 devices are receiving notifications and some devices can uninstall my app. Some working device notifications are not found mainly the latest device is not found. Even the device deleting me from my database does not even receive feedback that is not using my app.
Here is the code that I am using
function send_iphone_notification ($ message) {$ Sent = 0; * Select from $ Res = mysql_query ( "app, where Diwais_prkar = 'iOS') or die (Maiskil_ar ()); $ NUM_ROWS = mysql_num_rows ($ res); if ($ Num_rows) {$ Passphrase = 'Passphrase'; $ Badge = 1; $ ck = realpath ("ck.pem"); ////////////////////////////// /////////////////////////////////////////////// // / integrating ck.pem file to the $ ctx = stream_context_create (the APN);; Stream_context_set_option ($ ctx, 'ssl', 'local_cert', $ ck); Stream_context_set_option ($ ctx, 'ssl', 'passphrase', $ passphrase); // APNS server $ fp = stream_socket_client ( 'SSL: //gateway.push.apple.com: 2195', open connection $ $ err, $ errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx); If (! $ Fp) {return "IOS Connect Failed in field: $ err $ errstr "; // exit (" failed to connect: $ err $ errstr ". PHP_EOL);} $ date = date (" Y-M-D "); $ SNO = 0; while ($ Line = mysql_fetch_assoc ($ res)) $ $ sno ++; $ deviceTokan = $ line ['device_token']; $ DeviceID = $ line ['DEVICE_ID']; $ Message = $ message; If ($ message) {// Payload body $ body ['aps'] = array ('alert' => $ message, 'sound' = & gt; create 'default'); // Encrypt payload as JSON $ payload = json_encode ($ body); // $ deviceToken = $ line ['device_token']; //// Build iPod Device Tokens // Binary Notification $ msg = chr (0). Pack ('N', 32) Pack ('H *', $ DeviceToken) Pack ('n', strollon ($ payload)). $ Payload; // Send it to server $ result = fwrite ($ fp, $ msg, strlen ($ msg)); } If (! $ Result) {$ f + = 1; } Else {mysql_query ( "app set to update Krenset_deta = now () where Device_token = '$ deviceToken' and Device_Id = '$ deviceId' and Device_type = 'iOS'") or die (mysql_error ()); $ S + = 1; } // Close the connection to the server // Running feedback service Stream_contact_set_pash ($ ctx, 'ssl', 'local_cert', $ ck); Stream_context_set_option ($ ctx, 'ssl', 'passphrase', $ passphrase); $ Apns = stream_socket_client ('ssl: //feedback.push.apple.com: 2196', $ error, $ error string, 2, STREAM_CLIENT_CONNECT, $ ctx); If (! $ Apns) {// Resonance "Error $$ errcode: $ errstr \ n"; Return; } // Then echo 'APNS feedback connection established ... & lt; Br / & gt; '; $ Feedback_tokens = array (); $ Count = 0; $ Feedback_tokens = array (); // Read data on connection: while (! FIF ($ apns)) {$ data = fread ($ apns, 38); If (strangel ($ data)) {$ feedback_tokens [] = unpack ("N1timestamp / n1length / H * devtoken", $ data); }} Fclose ($ apns); Forex ($ Feedbak_taikens touch like device where the device as $ feet) {mysql_query ( "app" ". $ Ft [ 'devtoken']." ' ");} // response service terminated if ($ s & gt; = 1) returns "notification has been successfully sent to '$ s.' iPhones device '. $ Num_rows out and return' not sent notification '. $ F.' iPhone device out '. $ Num_rows;} And return 'no iPhone device found'; fclose ($ FP);} $ Message = '200 jobs have been updated'; $ = Send_iphone_notification ($ message)
This is my code, I think there is no mistake in this, but why notifications are not going on all the iPhone devices, Kripa Marie can help and not react. If there are no devices.
Also valid in this part:
< P> The Apple Push Notification Service includes the default Quality Service (QoS) component, which is a store-and-forward function Does not.If APN tries to give a notification device is stored for offline notification limited time, and when it is delivered to the device becomes available.
Only one recent information is stored for a particular app if multiple notifications are sent when the device is offline, then the reason for the disconnection of each new notification is made. This behavior of keeping only the latest notification is referred to as collaging notation.
If the device stays offline for a long time, any information that is being stored for it is discarded
No comments:
Post a Comment