android - ParseInstallation.getCurrentInstallation().saveInBackground();不工作

标签 android ios parse-platform push-notification

我在 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/

相关文章:

android - 在 Android 中的 Google map 中自动设置缩放级别

android - 通过蓝牙打印机 AGPtEK SC28 打印图像

android - 如何在android中等待语音识别的结果?

ios - `<PBX...` >` 试图用未知的 UUID 初始化一个对象。这可能是合并的结果,未知的 UUID 被丢弃

javascript - 无法序列化未保存的 Parse.Object 错误

android - 自定义首选项样式填充问题

ios - 需要 MAC 笔记本电脑配置才能开始处理 Xcode、iPhone 应用程序并推送到 AppStore

ios - 我如何在 zendrive iOS 中测试事故检测

ios - 解析 API 1.6.4 - 无法构建项目

iphone - 用于简单推送和获取的最佳 iOS 后端