简体   繁体   English

推送通知在TestFlight中不起作用,但在Xcode中起作用

[英]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. 到目前为止,通过Xcode安装该应用程序(基本上处于开发模式)时,我可以成功接收推送通知。 However, as soon as I install the app from TestFlight and try to use the new device token, the APN answers with BadDeviceToken . 但是,一旦我从TestFlight安装该应用程序并尝试使用新的设备令牌,APN就会回答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. 我确实做了自己的研究,但与此相关的所有问题似乎都已过时:尽管这些问题使用* .pem和* .p12证书,但我使用的是* .p8证书。 As far as I understood, p8 certificates are for both development and production, so I don't see the problem here? 据我了解,p8证书同时用于开发和生产,因此我在这里看不到问题吗?

I'm using the edamov\\pushok library from Github with this code: 我正在使用来自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());
}

So how can I setup the APN with a p8 certificate for production mode? 那么如何为生产模式设置带有p8证书的APN? Do I need to create a production certificate and somehow include it somewhere? 我是否需要创建生产证书,并以某种方式将其包含在某处?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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