我尝试删除与uniqueId
匹配的安装。这是我的Parse Cloud代码:
Parse.Cloud.define("removeInstallation", function(req, res) {
Parse.Cloud.useMasterKey();
var userId = req.params.uniqueId;
var query = new Parse.Query(Parse.Installation);
query.equalTo("uniqueId", userId);
query.each(function(installation) {
installation.remove();
});
query.find({
success: function(installations) {
res.success(installations);
},
error: function(error) {
res.error(error);
}
});
});
我从我的Android应用程序中调用它,如:
final String wifiMacAddress = getWifiMacAddress(context);
Map<String, String> params = new LinkedHashMap<String, String>();
params.put("uniqueId", wifiMacAddress);
ParseCloud.callFunctionInBackground("removeInstallation", params, new FunctionCallback<Object>() {
@Override
public void done(Object o, ParseException e) {
if (e != null)
throw new RuntimeException(e);
else Log.d("Test", o);
}
});
云功能调用正常,但未删除安装。我仍然可以在Parse.com仪表板中看到它。
如何删除它?
答案 0 :(得分:2)
解决。我打电话给remove()
而不是destroy()
。这是我现在的代码:
Parse.Cloud.define("removeInstallation", function(req, res) {
Parse.Cloud.useMasterKey();
var userId = req.params.uniqueId;
var query = new Parse.Query(Parse.Installation);
query.equalTo("uniqueId", userId);
query.find(function(installations) {
installations[0].destroy().then(
function() {
res.success("Destroyed");
},
function() {
res.error();
});
});
});