次のコードとして手動で通知を送信できます。
<?php
// Device token:
$deviceToken = 'xxxxxx';
$passphrase = 'xxxxx';
$badge = 1;
// Displays alert message here:
$message = 'Match Found!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/Users/Documents/iOS_Application_Developement/new/APNSPHP/ApnsPHP-master/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,
'badge' => $badge,
'sound' => 'default'
);
// 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;
// Close the connection to the server
fclose($fp);
?>
APNS PHP インテグレーションもありましたが、非常に多くのファイルがあります。私の目的では、有用なファイルは 1 つだけです。
APIを介してiOSで特定の出来事が発生したときに、このphpスクリプトを実行したいと思います。したがって、このコードを何らかの関数の下に記述し、特定の事象が発生したときにその関数を呼び出すことができます。それで、それを行う最良の方法は何ですか?5分ごとに実行される通知cronをどのように達成できますか?
どんな助けでも大歓迎です。