【问题标题】:Push notifications won't work in TestFlight, but do work from Xcode推送通知在 TestFlight 中不起作用,但在 Xcode 中起作用
【发布时间】:2018-02-15 14:06:39
【问题描述】:

我正在尝试为我的应用设置推送通知。 到目前为止,当应用程序通过 Xcode 安装时(基本上处于开发模式),我可以成功接收推送通知。但是,一旦我从 TestFlight 安装应用程序并尝试使用新的设备令牌,APN 就会回复 BadDeviceToken

我自己进行了研究,但所有关于此的问题似乎都已过时:虽然这些使用 *.pem 和 *.p12 证书,但我使用的是 *.p8 证书。据我了解,p8 证书是用于开发和生产的,所以我没有看到这里的问题?

我正在使用来自 Github 的 edamov\pushok 库和以下代码:

<?php
require '../../vendor/autoload.php';

use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;

$options = [
    'key_id' => 'xxx', // The Key ID obtained from Apple developer account
    'team_id' => 'xxx', // The Team ID obtained from Apple developer account
    'app_bundle_id' => 'xxx', // The bundle ID for app obtained from Apple developer account
    'private_key_path' => 'xxx (p8 certificate path)', // Path to private key
    'private_key_secret' => null // Private key secret
];

$authProvider = AuthProvider\Token::create($options);

$alert = Alert::create()->setTitle('Hello!');
$alert = $alert->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

//add custom value to your notification, needs to be customized
$payload->setCustomValue('key', 'value');

$deviceTokens = ['xxx (device token from TestFlight installation)'];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);



$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

foreach ($responses as $response) {
    echo($response->getApnsId());
    echo($response->getStatusCode());
    echo($response->getReasonPhrase());
    echo($response->getErrorReason());
    echo($response->getErrorDescription());
}

那么如何为生产模式设置带有 p8 证书的 APN?我是否需要创建生产证书并以某种方式将其包含在某处?

【问题讨论】:

    标签: ios apple-push-notifications


    【解决方案1】:

    在尝试通过 Testflight 安装应用时发送推送时,您是否启用了沙盒?

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多