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

从PHP推送通知向iOS发送变量?,php,objective-c,push-notification,apple-push-notifications,Php,Objective C,Push Notification,Apple Push Notifications,我正在使用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_socke

我正在使用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);
我成功地得到了它。我点击view按钮,尝试读取'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。发生什么事了


提前谢谢

使用字符串文字可能不是正确的解决方案;常量符号
uiapplicationaunchoptionsremotenotificationkey
在Apple的UIApplication.h头文件中定义;我会谨慎地避免使用预定义的符号,因为这些符号实际上是定义良好的公共API的一部分。
NSDictionary *pushInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"aps"]];