我正在尝试在Android上重新安装时删除重复安装。 我正在从ParseInstallation获取查询,但它无法正常工作。
我附上以下代码:
public boolean checkDuplicate(String id, ParseInstallation installation){
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereEqualTo("userId", id);
query.findInBackground(new FindCallback<ParseInstallation>() {
public void done(List<ParseInstallation> list, ParseException e) {
if (e == null) {
//Log.d("LISTA-CHECKDUPLICATE", "id " + list.size() );
for(int i = 0; i<list.size(); i++){
try {
list.get(i).delete();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} else {
Log.d("LISTA-CHECKDUPLICATE", "Error: " + e.getMessage());
}
}
});
return false;
}
答案 0 :(得分:2)
最后我用云代码解决了这个问题并在android上调用了这个函数:
Parse.Cloud.define("checkDuplicado", function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.Installation);
var objectId = request.params.objectId;
query.equalTo("userId", request.params.userId);
query.first().then(function(duplicate) {
if (typeof duplicate === "undefined" ) {
console.log("Duplicate does not exist,New installation");
response.success("Nueva Instalacion");
} else if(duplicate.id != objectId){
console.log("Duplicado existe..Intentando borrar " + duplicate.id );
//console.log("userId-NUEVO " + request.object.get("userId") + " ID: " + request.object.id);
// console.log("userId-DUPLICADO " + duplicate.get("userId") + " ID: "+ duplicate.id);
duplicate.destroy().then(function(duplicate) {
console.log("Duplicado borrado correctamente");
response.success("Duplicado borrado correctamente");
}, function() {
console.log(error.code + " " + error.message);
response.success("Error Borrando duplicado");
});
response.success("Check duplicados realizado correctamente");
}
else{
response.success("Check duplicados realizado correctamente");
}
}, function(error) {
console.warn(error.code + error.message);
response.success("Error");
});
});