Note that there are some explanatory texts on larger screens.

plurals
  1. POSend variables to iOS from PHP push notification?
    primarykey
    data
    text
    <p>I am using a PHP script to send push notifications to my device. Here is what I use</p> <pre><code>$ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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); echo 'Connected to APNS' . PHP_EOL; // Create the payload body $body['aps'] = array( 'alert' =&gt; $message, 'sound' =&gt; 'default', 'id' =&gt; '10' ); // 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; echo "to $deviceToken."; // Close the connection to the server fclose($fp); </code></pre> <p>I get it successfully. I tap the view button, and I am trying to read the 'id' variable like this: </p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Check for push notification info NSDictionary *pushInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (pushInfo) { // TODO: Pull the poke's info from our server and update the UI to display it NSLog(@"Here's the id: %@", [pushInfo valueForKey:@"id"]); } return YES; } </code></pre> <p>However, I don't get a NSLog when in mutitasking. I have yet to try it when I close the app because I cannot run console after you close out.</p> <p>I even tried this:</p> <pre><code>- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { // Handle the notificaton when the app is running NSLog(@"Recieved Notification %@",notif); } </code></pre> <p>If I send the notification when running, I don't even get a NSLog. What's going on?</p> <p>Thanks in advance! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload