我在 iOS 中创建了一个应用程序,它使用 Parse 来存储数据,还使用 Parse Push 在用户之间进行消息传递。我现在正在将应用程序转换为 Android 并尝试对两者使用相同的 Parse 后端。我正在成功上传/下载数据,我什至可以从 Android 用户向 iOS 用户发送消息,但我无法让我的 Android 设备接收消息。强调的问题似乎是我无法使安装工作。我正在从我的 onCreate 函数中调用这段代码:
Parse.enableLocalDatastore(this);
Parse.initialize(this, "id1", "id2");
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
ParseInstallation.getCurrentInstallation().saveInBackground();
调用此代码后,我检查数据库中是否有新安装,但没有显示任何内容。似乎 ParseInstallation.getCurrentInstallation().saveInBackground();
没有做任何事情。我错过了什么吗?
最佳答案
与给定设备上的安装关联的对象在解析安装表中没有一行,这就是您收到错误的原因,此问题有 2 种可能的解决方案:
- 卸载应用程序并重新安装(这是 Not Acceptable 解决方案),或
- 手动清除应用解析缓存。查看如何做的答案 那个
必须在调用 Parse.initialize 之前调用此方法...
public static boolean deleteInstallationCache(Context context) {
boolean deletedParseFolder = false;
File cacheDir = context.getCacheDir();
File parseApp = new File(cacheDir.getParent(),"app_Parse");
File installationId = new File(parseApp,"installationId");
File currentInstallation = new File(parseApp,"currentInstallation");
if(installationId.exists()) {
deletedParseFolder = deletedParseFolder || installationId.delete();
}
if(currentInstallation.exists()) {
deletedParseFolder = deletedParseFolder && currentInstallation.delete();
}
return deletedParseFolder;
}
关于android - ParseInstallation.getCurrentInstallation().saveInBackground();不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27628392/