Ionic 3上的OneSignal推送通知:所有包含的玩家都没有订阅

时间:2018-06-07 16:41:02

标签: android firebase ionic-framework notifications onesignal

我正在使用Ionic 3开发Android应用程序,我想使用工具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();

以下是我在我的节点webservice上使用的代码:

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']}

0 个答案:

没有答案