使用 ionic 3 注册设备时出现 Back4app 问题

Back4app issue in registering device with ionic 3

我正在尝试使用 back4app 进行推送通知。为此,我安装了 back4app 的 ionic sdk (https://www.back4app.com/docs/ionic/parse-ionic-sdk),就像这样

npm install parse

然后在我的 app.component.ts 中导入了 parse

import Parse from 'parse';

并在平台就绪

Parse.serverURL = "https://parseapi.back4app.com/";
Parse.initialize("APP_ID_HERE", "JAVASCRIPT_KEY"); //I have used real keys from back4app dashboard.

let  install = new Parse.Installation();

install.save(null, {
    success: (install) => {
      // Execute any logic that should take place after the object is saved.
       // console.clear();
        console.error('New object created with objectId: ' + install.id);
    },
    error: (install, error) => {
      // Execute any logic that should take place if the save fails.
      // error is a Parse.Error with an error code and message.
      //console.clear();
      console.error('Failed to create new object, with error code:' + error.message.toString());
    }
});

当我在设备中执行 Ionic 服务或测试时,它应该将 device/installation id 注册到他们的后端,但它给出 400 Bad Request error on https://parseapi.back4app.com/classes/_Installation 错误是 -

{"code":135,"error":"deviceType must be specified in this operation"}

我不知道在哪里提到 deviceType 因为他们的文档看起来不太好。

谁能帮我解决这个问题?

他们的文档中没有提到这一点,但我在他们的一个示例中找到了它。

正在替换 -

let  install = new Parse.Installation();

 let  install = new Parse.Installation();
 install.set("deviceType", platform.platforms().toString());

问题已解决。

Here is the link to their repository

Parse SDK 现在支持 Promises

我建议使用它而不是传递回调。

您可以通过以下方式完成:

install.save().then(() => {
  // success
}, err => {
  // error
})