![](/img/trans.png)
[英]Push notifications with Parse, Testflight and Xcode 6 doesn't work
[英]Push notifications won't work in TestFlight, but do work from Xcode
我正在嘗試為我的應用設置推送通知。 到目前為止,通過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? 我是否需要創建生產證書,並以某種方式將其包含在某處?
如果通過Testflight安裝了應用程序,則在嘗試發送推送時,是否使沙盒保持啟用狀態?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.