向离子3注册设备中的Back4app问题

时间:2018-07-02 08:46:17

标签: ionic-framework ionic3 back4app

我正在尝试使用back4app进行推送通知。为此,我像这样安装了back4app的离子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,因为他们的文档似乎不太好。

有人可以帮我吗?

2 个答案:

答案 0 :(得分:2)

Parse SDK现在支持Promises

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

您可以通过以下方式实现这一目标:

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

答案 1 :(得分:1)

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

替换-

let  install = new Parse.Installation();

使用

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

解决了这个问题。

Here is the link to their repository

相关问题