从PHP推送通知向iOS发送变量


Send variables to iOS from PHP push notification?

我使用PHP脚本发送推送通知到我的设备。下面是我使用的

$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' => $message,
'sound' => 'default',
'id' => '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);

我成功了。我点击视图按钮,我试图像这样读取'id'变量:

- (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;
}

然而,在多任务处理时,我没有得到NSLog。当我关闭应用程序时,我还没有尝试过,因为关闭后我无法运行控制台。

我甚至试过这个:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
}

如果我在运行时发送通知,我甚至不会得到NSLog。这是怎么呢

提前感谢!

NSDictionary *pushInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"aps"]];