1

我正在尝试back4app用于推送通知。为此,我已经像这样安装了back4appionic sdk ( https://www.back4app.com/docs/ionic/parse-ionic-sdk )

npm install parse

然后在我app.component.ts导入的解析中

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 服务或测试时,它应该将设备/安装 ID 注册到他们的后端,但它给出400 Bad Request error on https://parseapi.back4app.com/classes/_Installation的错误是 -

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

我不确定在哪里提及deviceType,因为他们的文档似乎不太好。

有人可以帮我吗?

4

2 回答 2

3

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

更换 -

let  install = new Parse.Installation();

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

解决了这个问题。

这是他们存储库的链接

于 2018-07-02T09:09:29.210 回答
2

Parse SDK 现在支持Promises.

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

您可以通过以下方式实现:

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

于 2018-07-03T15:51:51.953 回答