Я пытаюсь отправить Push-уведомления в приложение ios. Они отлично работают для приложения, которое я загружаю через магазин приложений, но не работают, когда я устанавливаю бета-версию с помощью Testflight. Этот вид поражает цель, так как я хочу протестировать новые типы уведомлений и делать правильные вещи в приложении.
Я думаю, что делаю все правильно:
- Зарегистрируйтесь для получения уведомлений в приложении и получите токен устройства
- отправить токен устройства на мой сервер
- отправить уведомление на устройство, используя APNS в узле.
Проблема в том, что когда я отправляю уведомление с сервера в приложение, загруженное с Testflight, я получаю ошибку BadDeviceToken. Из App Store работает отлично.
Код в Node выглядит примерно так:
let util = require('util');
let apn = require('apn');
class PushNotification {
constructor(production) {
production = !!production;
this.apnProvider = new apn.Provider({
token: {
key: './apns.p8', // Path to the key p8 file
keyId: 'xxxxxxxxx', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
teamId: 'YYYYYYYY' // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
},
production: production // Set to true if sending a notification to a production iOS app
});
if (production) {
process.env.NODE_ENV = "production";
}
}
sendNotificationApple(deviceToken, alert, payload, badge) {
if (deviceToken && (alert || badge)) {
let note = new apn.Notification();
note.topic = 'com.xxx.xxx';
note.expiry = Math.floor(Date.now() / 1000) + 3600 * 24 * 2; // Expires 2 days from now
if (badge != undefined && badge != -1) {
note.badge = badge;
}
note.alert = alert;
if (payload) {
note.payload = payload;
}
this.apnProvider.send(note, deviceToken).then(function (result) {
console.log(util.inspect(result, false, null));
});
}
}
}