我在 Symfony 上从事项目,但我在这个 github 存储库中遇到 NotificationPusher 问题:https://github.com/Ph3nol/NotificationPusher
我解释一下,我设法用所有必要的信息创建了我的钱包,我得到了一个推送令牌以及我在存折注册中更新我的钱包所需的一切,但我无法在 IOS 上发送推送通知。 通知是可见的,但只有在我刷新钱包时才可见。
这里是我使用的代码,是从github上的demo复制过来的。 我检查了我是否正确获取了所有信息:
public function sendIOS(string $pushToken, $notification = null): void
{
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);
// Then declare an adapter.
$apnsAdapter = new ApnsAdapter([
'certificate' => __DIR__ . '/../../AppleCertificate/Certificate.pem',
'passPhrase' => $this->params->get('IOS_PASS_PASSPHRASE'),
]);
// Set the device(s) to push the notification to.
$devices = new DeviceCollection([
new Device($pushToken, ['badge' => 1])
]);
// Then, create the push skel.
$message = new Message('This is an example.', array(
'badge' => 1,
'sound' => 'example.aiff',
'actionLocKey' => 'Action button title!',
'locKey' => 'localized key',
'locArgs' => array(
'localized args',
'localized args',
'localized args'
),
'launchImage' => 'image.jpg',
'custom' => array('custom data' => array(
'we' => 'want', 'send to app'
))
));
// Finally, create and add the push to the manager, and push it!
$push = new Push($apnsAdapter, $devices, $message);
$pushManager->add($push);
$pushManager->push();
}
此外,我检查了退货并试图转储一个可能的错误,但一切都告诉我通知已发送,但它从未出现在我的手机上,除非我刷新钱包。
感谢帮助! :)