我正在尝试使用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,因为他们的文档看起来不太好。
有人能帮我吗??
发布于 2018-07-02 09:09:29
他们的文档中没有提到这一点,但我在他们的一个例子中发现了这一点。
取代-
let install = new Parse.Installation();使用
let install = new Parse.Installation();
install.set("deviceType", platform.platforms().toString());解决了这个问题。
发布于 2018-07-03 15:51:51
解析SDK现在支持Promises。
我建议使用它而不是传入回调。
您可以通过以下方式实现这一点:
install.save().then(() => {
// success
}, err => {
// error
})
https://stackoverflow.com/questions/51132194
复制相似问题