【问题标题】:Notification cron in PHP for iphone Application适用于 iPhone 应用程序的 PHP 中的通知 cron
【发布时间】:2013-06-20 14:10:48
【问题描述】:

我可以按照以下代码手动发送通知。

<?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 集成。但是文件太多了。就我的目的而言,只有一个文件有用。

现在我想通过我的 API 在 iOS 中发生某些事件时运行这个 php 脚本。所以我可以在某个函数下编写这段代码,并在某些事件发生时调用该函数。那么最好的方法是什么?以及如何实现每 5 分钟运行一次的通知 cron?

我们将不胜感激。

【问题讨论】:

标签: php ios cron apple-push-notifications


【解决方案1】:

/etc/cron.d/中创建一个cron条目

 */5 * * * * root cd /path_to_your_script/ && php your_script.php >> /var/some.log &2>&1

【讨论】:

  • 你能详细描述一下吗..我看不懂这里写的是什么?
  • 这是 cron 文件中的一个条目。 */5 表示每 5 分钟运行一次。另一个 * 代表小时、星期几、月份中的某一天、月份等。有关详细信息,请参阅 en.wikipedia.org/wiki/Cron
  • 我想在 iOS 应用程序的 API 级别实现。不在 liux 端。所以这不是答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 2018-07-29
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多