php - "Delivered Message to APNS" but not showing notification in Production with ios13 (PHP)
问题描述
i have a problem with Notifications in ios13. If i use gateway.sandbox i can see the notification, but i'have downloaded the app directly from AppStore. Instead using gateway.apple i see 'Delivered Message to APNS', but nothing on my device. I also tried to recreate the Certificate, .p12 and .pem file.
Any idea? Thank you
This is my php
public function iOS($data, $devicetoken)
{
// $tHost = 'gateway.sandbox.push.apple.com';
$tHost = 'gateway.push.apple.com';
$tPort = 2195;
$tCert = 'pushcert.pem';
$tPassphrase = 'pushcertpsw12';
$tToken = $devicetoken;
$tSound = 'default';
$tPayload = 'APNS payload';
$tBody['aps'] = array(
'apns-priority' => 10,
'badge' => +1,
'alert' => $data['mtitle'] .' ' .$data['mdesc'],
'sound' => 'default'
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
if (!$tSocket)
exit ('APNS Connection Failed:' .$error. ' ' .$errstr . PHP_EOL);
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;
// Send the Notification to the Server.
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
echo 'Delivered Message to APNS' . PHP_EOL;
else
echo 'Could not Deliver Message to APNS' . PHP_EOL;
// Close the Connection to the Server.
fclose ($tSocket);
解决方案
APNS令牌有两种不同的环境;沙盒和生产。它们需要完全独立的设置、权限、注册和推送设置。将沙盒 APNS 通知推送到生产令牌将不起作用,与将生产 APNS 推送到沙盒令牌相同。
如果您已在 Sandbox 中验证但未在生产中验证,则可能需要复制所有权限和证书以进行生产。还要仔细检查您使用 PHP 代码推送到的位置,并确保它是正确的环境(沙盒与产品)。
推荐阅读
- java - 字符串常量池是否也适用于单例注释变量?
- c - CS50(2021) 滤镜 - 模糊
- c - AOSP 中间件中的致命信号 11 (SIGSEGV)
- next.js - 尝试获取 pancakeswap api 时出现获取错误
- go - 如何理解 go 闭包中的作用域
- css - 部署的项目。样式适用于 chrome 模拟器,但不适用于设备
- javascript - 渲染错误未定义不是一个对象(评估'this.props.navigation.navigate')react-native
- node.js - 如何将 Msal 节点令牌缓存存储在数据库中并在应用重新启动时停止清除缓存
- r - 如何为 lmer 公式自动更改随机和固定效果的组合(在 R 中)
- ios - iOS 中的 os_signpost 和 mxSignpost 有什么区别?