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

Rya*_*yer 3 android push-notification ios parse-platform

我在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();
Run Code Online (Sandbox Code Playgroud)

在调用此代码后,我检查数据库中的新安装,但没有任何显示.似乎ParseInstallation.getCurrentInstallation().saveInBackground();没有做任何事情.我错过了什么吗?

Len*_*Bru 6

与给定设备上的安装相关联的对象在解析安装表中没有行,这就是您收到错误的原因,此问题有两种可能的解决方案:

  • 卸载应用程序,并重新安装它(这是一个不可接受的解决方案),或
  • 手动清除应用程序解析缓存.看看如何做到这一点的答案

在调用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;
    }
Run Code Online (Sandbox Code Playgroud)