【发布时间】:2019-01-10 10:39:31
【问题描述】:
我正在处理推送通知,我想使用 php 向 IOS 发送聊天推送通知。但是当我向 apns(Apple Push Notification Server)发送 5 个推送通知时,apns 会丢弃旧的推送通知,并在设备上线时仅向设备发送最新的推送通知。
我在互联网上搜索解决方案,我找到的一个解决方案是设置通知到期时间。所以我通过我的实际问题没有解决来实现这个解决方案。
有什么办法可以解决我的问题。建议任何有用的解决方案或参考网站。
IOS push notification with PHP
下面是我的示例代码
public function sendIOSNotification($tokens, $data, $envoirement = 'production') {
try {
$payload = json_encode($this->setIosNotificationDataParameters($data));
$deviceTokens = str_replace(array(' ', '<', '>'), '', $tokens['ios']);
// FUNCTION NOTIFICATIONS
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', config('push-notification.appNameIOS.certificate_' . $envoirement));
stream_context_set_option($ctx, 'ssl', 'passphrase', 'push');
//send notification
$fp = stream_socket_client(
config('push-notification.appNameIOS.ios_push_notification_' . $envoirement), $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx
);
$res = [];
foreach ($deviceTokens as $deviceToken) {
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken)
. pack('n', strlen($payload)) . $payload
.pack('N', time()).pack('N', time() + 86400);
$res = json_encode($result);
}
fclose($fp);
\Log::info("=== IOS Notification Send Successfully ===");
return true;
} catch (\Exception $ex) {
$messages = $ex->getMessage() . '::' . $ex->getFile() . '( ' . $ex->getLine() . ' )';
\Log::ifno("===Push Notificaion Exception===");
\Log::ifno($messages);
return true;
}
}
【问题讨论】:
标签: php laravel apple-push-notifications