2015-05-26 25 views
5

Tôi sử dụng phân tích cú pháp để xử lý thông báo đẩy. Bởi vì tôi đã có cơ sở dữ liệu của riêng mình, tôi sử dụng phân tích cú pháp để lưu trữ dữ liệu cài đặt. (Không sử dụng ParseUser để đăng nhập và đăng xuất trong ứng dụng) Khi tôi đăng xuất ứng dụng, tôi muốn xóa cài đặt của mình.Android không thể xóa cài đặt phân tích cú pháp

ParseInstallation installation = ParseInstallation.getCurrentInstallation(); 
installation.deleteInBackground(new DeleteCallback() { 
    @Override 
    public void done(ParseException ex) { 
     Log.d(TAG, "ParseInstallation deleteInBackground done"); 
     if (ex != null) { 
      Log.e(TAG, "ParseInstallation deleteInBackground", ex); 
     } 
    } 
}); 

Sau đó, tôi đã nhận lỗi sau:

com.parse.ParseRequest$ParseRequestException: forbidden 
     at com.parse.ParseRequest.newPermanentException(ParseRequest.java:391) 
     at com.parse.ParseRESTCommand.onResponse(ParseRESTCommand.java:197) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:258) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:254) 
     at bolts.Task$14.run(Task.java:796) 
     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105) 
     at bolts.Task.completeAfterTask(Task.java:787) 
     at bolts.Task.continueWithTask(Task.java:599) 
     at bolts.Task.continueWithTask(Task.java:610) 
     at bolts.Task$12.then(Task.java:702) 
     at bolts.Task$12.then(Task.java:690) 
     at bolts.Task$14.run(Task.java:796) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
     at java.lang.Thread.run(Thread.java:841) 

Cảm ơn!

+0

Tôi không thể hiểu những gì bạn đang cố gắng để đạt được. Lớp cài đặt, theo tên, có nghĩa là lưu trữ các cài đặt ứng dụng của bạn. Tiếp tục ... một đối tượng cài đặt mới được tạo ra mỗi lần bạn gọi khởi tạo (key1, key2) lần đầu tiên. – Aashir

+0

Tôi muốn xóa bản ghi cài đặt được lưu trữ trong phân tích cú pháp. Vì vậy, người dùng sẽ không nhận được bất kỳ thông báo đẩy nào. – Lilian

+0

Đối với thông báo đẩy? Bạn đã đăng ký người dùng đã đăng nhập vào một kênh chưa? – Aashir

Trả lời

1

Tôi nghĩ bạn đang cố thực hiện yêu cầu với người dùng không có đủ quyền tác giả để thực hiện điều đó. Có thể, bạn đang thực hiện yêu cầu này khi phiên đã bị hủy (để đăng xuất), thay vì thực hiện nó trước khi phá hủy nó.

1

Bạn phải xóa nó khỏi Cloud Code bằng khóa chính.

Trong client android:

   //clear the installation backend 
      HashMap<String, String> params = new HashMap<>(); 
      String idToken = ParseInstallation.getCurrentInstallation().getInstallationId(); 
      params.put("installationId", idToken); 
      ParseCloud.callFunctionInBackground("removeInstallation", params, new FunctionCallback<String>() { 
       @Override 
       public void done(String response, ParseException e) { 
        if (e == null) { 
         //clear the local chache 
         ParseEasyAccess.clearParse(); 
        } else { 
         e.printStackTrace(); 
        } 
       } 
      }); 

Và sau đó trong Bộ luật Cloud:

  Parse.Cloud.define("removeInstallation", function(request, response) { 

     Parse.Cloud.useMasterKey(); 

     var installationId = request.params.installationId; 

     var query = new Parse.Query(Parse.Installation); 
     query.equalTo("installationId", installationId); 

     query.find(function(installations) { 
      installations[0].destroy().then(
       function() { 
        response.success("Destroyed"); 
       }, 
       function() { 
        response.error("Failed"); 
       }); 
     }); 

    }); 

Và nếu bạn muốn cũng để xóa các cài đặt được lưu trữ trên thiết bị của bạn, làm như sau:

  1. Tạo gói có tên com.parse

  2. Crate một lớp, ví dụ như MyParseTools.

  3. Thực hiện một liks phương pháp tĩnh như vậy:

    public static void clearParseInstallation() { 
    ParseInstallation.getCurrentInstallationController().clearFromDisk(); 
    ParseInstallation.getCurrentInstallationController().clearFromMemory();} 
    
Các vấn đề liên quan