2
PHPスクリプトを使用してデバイスにプッシュ通知を送信しています。ここに私が使用しているものがありますPHPプッシュ通知からiOSに変数を送信しますか?
$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;
}
ときmutitaskingでしかし、私はのNSLogを得ることはありません。私はあなたが閉じた後にコンソールを実行することができないので、私はアプリを閉じるときにまだそれを試してみました。
私もこれを試してみました:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
}
が実行しているとき、私は通知を送信した場合、私ものNSLogを得ることはありません。どうしたの?
ありがとうございます!
文字列リテラルの使用はおそらく正しい解決法ではありません。定数シンボル 'UIApplicationLaunchOptionsRemoteNotificationKey'はAppleのUIApplication.hヘッダーファイルで定義されています。実際にはよく定義された公開APIの一部であるため、あらかじめ定義されたシンボルを控えることには慎重になります。 –