Push-уведомление OneSignal на Ionic 3: все включенные плееры не подписаны - PullRequest
0 голосов
/ 07 июня 2018

Я разрабатываю приложение для Android с использованием Ionic 3 и хочу использовать push-уведомления с помощью инструмента OneSignal.Вот код, который я использую в своем основном компоненте:

  let iosSettings = {
    kOSSettingsKeyAutoPrompt: true,
    kOSSettingsKeyInAppLaunchURL: false
  }

  this.oneSignal
    .startInit(APP_ID, GOOGLE_PROJECT_NUMBER)
    .iosSettings(iosSettings);

  this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);

  this.oneSignal
    .handleNotificationReceived()
    .subscribe((notification: OSNotification) => {
      console.log(notification)
    });

  this.oneSignal.endInit();

А вот код, который я использую в своем веб-сервисе моего узла:

function sendNotification(scheduling) {
    const schedulingID = scheduling.email + scheduling.date;

    const message = {
        app_id: APP_ID,
        headings: {"en": MY_APP_NAME},
        contents: {"en": "Scheduling confirmed!"},
        data: {"agendamento-id": schedulingID},
        included_segments: ["All"]
    };

    const headers = {
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": "Basic " + REST_API_KEY
    };

    const options = {
        host: "onesignal.com",
        port: 443,
        path: "/api/v1/notifications",
        method: "POST",
        headers: headers
    };

    console.log("Sending notification...");
    const req = https.request(options, function (res) {
        res.on('data', function (data) {
            console.log("Response:");
            console.log(JSON.parse(data));
        });
    });

    req.on('error', function (e) {
        console.log("ERROR:");
        console.log(e);
    });

    req.write(JSON.stringify(message));
    req.end();
}

Но, когда я запускаю AndroidПриложение на моих устройствах, я получаю сообщение об ошибке:

    {id: '', recipients: 0, errors: ['All included players are not subscribed']}
...