I am trying to set up push notifications in my iOS7 app and am running into issues.
Basically the push never shows up I when through the process of creating the certificates and the provisioning profiles. Currently I only have it built for development and will get the distribution one made up when I am ready to submit it. But in the development setup everything appears to be correct. I made a PHP file to create the message in dictionary format and I believe everything is correct on that side of things. The passthru code is addedd correctly and I connect to the APNS server correctly (the development side) I can tell this because when I make my pass code incorrect it does fail.
From going through the iOS development documents related to PUSH I added a persistantConnection profile onto my phone and view the detailed log files and according to that data it should also be working.
I am not totally familiar with reading this data but the good things I was told to look for were there and the bad things were not.
I will attach my PHP script and the log from the device
PHP script
session_start();
if($_POST['message']){
$deviceToken = array();
$deviceToken[0]="xxxx3ee0 3xxxx973 6bxxxxea 2843xxxx dx5xbx1x x4x8x0xe 7xx65xx9 x61xx01x";
$payload ='{
"aps" :
{ "alert" : "'.$_POST['message'].'"
, "badge" : 1
, "sound" : "bingbong.aiff"
}
}';
/*
$payload = '
{
"aps": {
"alert": "alert",
"sound": "default"
},
"message": "'.$_POST['message'].'",
"id": 1234
}
';
*/
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'ck.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "xoxoxoxo");
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if(!$apns) {
print"Stream failed to create ". $error. " ".$errorString;
return;
} else {
print"Message Sent";
}
foreach($deviceToken as $key=>$value){
$apnsMessage = chr(0) . pack("n",32) . pack('H*',str_replace(' ', '', $value)) . pack ("n", strlen($payload)) . $payload;
// $apnsMessage = chr(0) . chr(0) . chr(32) . @pack('H*', str_replace(' ', '', $value)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
print "<BR>Message Delivered - ". $payload;
}
fclose($apns);
}
?>
<form action="blanket.php" method="post">
<input type="text" placeholder="message" name="message">
<input type="submit" value="submit">
</form>
According to the doc this is what I am looking for
I see this:
Look for messages from the apsd process. Ideally you'll see Connected to courier x-courier.sandbox.push.apple.com where x is a small integer. That indicates that the device has successfully established its persistent connection to the push service.
I do not see this:
You might on the other hand see Disconnecting in response to connection failure. That means that the persistent connection failed. In that case, the goal is to figure out what's going on with your network that's causing the connection failure. Check that no firewalls are blocking TCP traffic on port 5223.
I do not see this:
The message connection set ignored topics means that the user chose to turn off notifications for the apps listed in the message. That will be followed by Sending filter message for enabled hashes which is where iOS actually sends the enabled and ignored topics to APNs.
I do not see this:
The message Failed to parse JSON message payload indicates that the JSON dictionary in the notification payload is not in valid JSON format.
The bad part is I also do not see this:
The message Received message for enabled topic means that the device received a notification from the push service.
DATA FROM LOG search for this criteria "Connected to Courier" showing good info
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16e49ff0> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference NonCellular shouldUseDualChannel YES. Connected on 1 interfaces.
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16d78f70> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference NonCellular shouldUseDualChannel YES. Connected on 1 interfaces.
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Connected to courier 2-courier.sandbox.push.apple.com (17.149.34.142) connection: <APSCourierConnection: 0x16d79810> onInterface: NonCellular
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Connected to courier 30-courier.push.apple.com (17.149.36.134) connection: <APSCourierConnection: 0x16d4a380> onInterface: NonCellular
2014-03-14 14:56:55 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for PushConnectionConnected
2014-03-14 14:56:55 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for PushConnectionConnected
2014-03-14 14:57:52 -0700 apsd[83]: <APSCourier: 0x16d78f70> - systemDidLock and we're connected via noncellular, sending inactive ping to the server
2014-03-14 14:57:52 -0700 apsd[83]: <APSCourier: 0x16e49ff0> - systemDidLock and we're connected via noncellular, sending inactive ping to the server
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourierConnection: 0x16d4a380> WWAN is connected; to be consistent, closing the non-cellular connection
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> courierConnection <APSCourierConnection: 0x16d4a380> asked us to disconnect stream on interface NonCellular. Connected on 2 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> courierConnection <APSCourierConnection: 0x16d4a380> asked us to disconnect stream on interface NonCellular. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference None shouldUseDualChannel NO. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> _connectStream - caller is ensuring that we are connected. We are so there's nothing to do here. - Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourierConnection: 0x16d79810> WWAN is connected; to be consistent, closing the non-cellular connection
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> courierConnection <APSCourierConnection: 0x16d79810> asked us to disconnect stream on interface NonCellular. Connected on 2 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> courierConnection <APSCourierConnection: 0x16d79810> asked us to disconnect stream on interface NonCellular. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference None shouldUseDualChannel NO. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> _connectStream - caller is ensuring that we are connected. We are so there's nothing to do here. - Connected on 1 interfaces.
As far as I can tell it should be working but it is not.
Any ideas?
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
Let's start with Android. The Android OS is designed to listen for push messages and upon receiving one, wake up the appropriate Android app to handle the push message, regardless of whether the app is closed or not.
What to Know. Swipe up on your iPhone's lock screen to pull up the Notification Center. You can also reveal the Notification Center when your iPhone is unlocked by swiping down from the top-left corner of the screen. There is no way to recall deleted notifications.
You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.
Can you try to remove the white space between the device token so that your device token will look like
$deviceToken[0]="xxxx3ee03xxxx9736bxxxxea2843xxxxdx5xbx1xx4x8x0xe7xx65xx9x61xx01x";
As per my knowedge , device token should not contain any white space & symbols < , >
Also check the return code from request & feedback service to give you information about failed push notifications as mentioned here
Please let me know if it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With