简体   繁体   中英

Push notifications won't work in TestFlight, but do work from Xcode

I'm trying to set-up push notifications for my app. I'm so far that, when the app is installed through Xcode (in development mode basically), I can successfully receive push notifications. However, as soon as I install the app from TestFlight and try to use the new device token, the APN answers with BadDeviceToken .

I did do my own research, but all the questions on this seem to be outdated: While these used *.pem and *.p12 certificates, I'm using a *.p8 certificate. As far as I understood, p8 certificates are for both development and production, so I don't see the problem here?

I'm using the edamov\\pushok library from Github with this code:

<?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());
}

So how can I setup the APN with a p8 certificate for production mode? Do I need to create a production certificate and somehow include it somewhere?

如果通过Testflight安装了应用程序,则在尝试发送推送时,是否使沙盒保持启用状态?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM