本文介绍了删除 android parse.com 上的重复安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 android 上重新安装时删除重复的安装.我正在从 ParseInstallation 获取查询,但它不起作用.
I'm trying delete duplicate installation when reinstall on android.I'm doing get query from ParseInstallation but it is not working.
我在下面附上我的代码:
I attach my code below:
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;
}
推荐答案
最后我用云代码解决了这个问题,并在android上调用了这个函数:
Finally I solved this with cloud code and calling this function on 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");
});
});
这篇关于删除 android parse.com 上的重复安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!