错误:使用 OneSignal 推送注册时遇到错误:错误域=OneSignalError Code=400”

qas*_*oui 7 xcode push-notification ionic-framework onesignal

我在将一个信号集成到我的 iOS 应用程序时遇到了一个问题,我遵循了离子指南和一个信号中的所有内容,但收到此错误

错误:在使用 OneSignal 推送注册过程中遇到错误:错误域=OneSignalError Code=400 "(null)" UserInfo={returned={ errors = ( "app_id not found。您可能缺少 Content-Type: application/json 标头。 "); }}

我确定app_id是正确的

任何机构帮助这是我的代码:

platform.ready().then(() => {


  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  statusBar.styleDefault();
  splashScreen.hide();

if(platform.is('ios')){
    console.log('platform is ios using onsignail for ios');
    this.oneSignal.startInit('bae0c3e1-bc4e-49ab-9274-18635XXXXX', );

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

this.oneSignal.handleNotificationReceived().subscribe(() => {
    // do something when notification is received
});

this.oneSignal.handleNotificationOpened().subscribe(() => {
    // do something when a notification is opened
});

this.oneSignal.endInit();
Run Code Online (Sandbox Code Playgroud)

}

这是 xcode 控制台中的输出

错误:在使用 OneSignal 推送注册过程中遇到错误:错误域=OneSignalError Code=400 "(null)" UserInfo={returned={ errors = ( "app_id not found。您可能缺少 Content-Type: application/json 标头。 "); }} 2018-09-20 09:48:39.056130+0100 Baby Fashion[514:115983] 错误:使用 OneSignal 注册电子邮件时遇到错误:(空)

感谢您的帮助

小智 0

您需要尽快启动OneSignal,否则当应用程序尝试将插件与ios挂钩时,它不会提供app_id,并且会抛出错误。

并且您在platform.ready方法内部有代码,因此在插件尝试挂钩时 oneSignal 需要时间来初始化。

您还需要设置 firebase 项目 id 才能为 Android 应用程序启用推送通知。