简体   繁体   English

解析本地数据存储区:强制关闭应用程序后,无法从网络访问ACL保护的对象吗? (机器人)

[英]Parse Local Datastore: I can't access ACL secured objects from the network after force closing the app? (Android)

After a successful login I'm calling: 成功登录后,我会打电话给:

ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.isAuthenticated()

Now if I switch to another app via the home button or multitasking and return to my app the currentUser is still authenticated. 现在,如果我通过主页按钮或多任务切换到另一个应用程序并返回到我的应用程序,则仍然对currentUser进行身份验证。

But if I force close the app and then reopen it the currentUser is not authenticated. 但是,如果我强制关闭该应用程序,然后重新打开它,则当前用户未通过身份验证。 Therefore it seems that I can't access any objects from the network which have the default Access Control List (ACL) added to them via: 因此,看来我无法通过以下方式访问网络中添加了默认访问控制列表(ACL)的任何对象:

Parse.enableLocalDatastore(this);
ParseACL.setDefaultACL(new ParseACL(), true);

Update with sample code: 用示例代码更新:

    // Pinning
    ParseObject gameScore = new ParseObject("GameScore");
    gameScore.put("score", 1337);
    gameScore.put("playerName", "Sean Plott");
    gameScore.put("cheatMode", false);
    gameScore.pinInBackground("NEW_GAMESCORES", null);

    // Syncing Local Changes
    ParseQuery<ParseObject> localQueryNewScores = ParseQuery
            .getQuery("GameScore");
    localQueryNewScores.fromPin("NEW_GAMESCORES");

    localQueryNewScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> scores, ParseException e) {

            Log.d("score", "New scores = " + scores.size());

            for (ParseObject score : scores) {
                score.saveInBackground();
                score.unpinInBackground("NEW_GAMESCORES", null);

                score.pinInBackground("GAMESCORES", null);
            }
        }
    });

    // Syncing Network Changes
    ParseQuery<ParseObject> networkQueryScores = ParseQuery
            .getQuery("GameScore");

    // Query for new results from the network.
    networkQueryScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(final List<ParseObject> scores, ParseException e) {

            Log.d("score", "Network scores = " + scores.size());

            // Remove the previously cached results.
            ParseObject.unpinAllInBackground("GAMESCORES",
                    new DeleteCallback() {
                        public void done(ParseException e) {
                            // Cache the new results.
                            ParseObject.pinAllInBackground("GAMESCORES",
                                    scores);
                        }
                    });
        }
    });

    // Querying the Local Datastore
    ParseQuery<ParseObject> localQueryScores = ParseQuery
            .getQuery("GameScore");
    localQueryScores.fromPin("GAMESCORES");

    localQueryScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> scores, ParseException e) {
            Log.d("score", "Local scores = " + scores.size());
        }
    });

Log output just after I've ran the code several times: 我多次运行代码后才记录日志输出:

New scores = 2
Local scores = 0
Network scores = 0

New scores = 0
Local scores = 0
Network scores = 2

New scores = 2
Local scores = 2
Network scores = 2

New scores = 1
Local scores = 2
Network scores = 4

Log output just after I've force closed the app: 我强制关闭应用程序后的日志输出:

New scores = 0
Local scores = 4
Network scores = 0

New scores = 2
Local scores = 0
Network scores = 0

As you can see at Network scores = 0 after the force close I am unable to query any results from the network where I // Query for new results from the network to update the pinned objects in the Local Datastore with new results from the network. 如您所见,在强制关闭后Network scores = 0 ,我无法从网络中查询任何结果,我// Query for new results from the network从网络中// Query for new results from the network更新本地数据存储区中的固定对象。 This happens even though I am constantly connected to the internet after the first login. 即使我在首次登录后仍不断连接到互联网,也会发生这种情况。

But as I need to sync back changes from the network to the Local Datastore I'm depending on this query. 但是由于我需要将更改从网络同步回本地数据存储,所以我要依赖此查询。

So how can I still query the network for objects that are stored with ACL added to the currentUser, after I force close the app? 因此,在我强制关闭应用程序之后,如何仍可以在网络中查询用ACL存储到currentUser中的对象?

Update 2 更新2

I found others with the same problem which has been reported here: developers.facebook.com/bugs/702967266408226 我发现其他人也遇到了同样的问题,这里已经报道过: developers.facebook.com/bugs/702967266408226

It seems to be a bug in the new Parse Android SDK 1.5. 在新的Parse Android SDK 1.5中似乎是一个错误。 I will update this post as soon as it's clear that my problem was related to the reported bug. 很明显我的问题与所报告的错误有关,我将立即更新此帖子。

也许将密码保存到文件,如果在强制关闭后重新打开应用程序,则使用此保存的密码登录?

您可以将用户名和密码保存在SharedPreferences中,然后在用户重新打开您的应用程序时再次登录。

I think you could just check to see whether getCurrentUser is null or not instead of using isAuthenticated . 我认为您可以只检查getCurrentUser是否为null而不是使用isAuthenticated

boolean isLoggedIn = ParseUser.getCurrentUser() != null;

isAuthenticated states: isAuthenticated状态:

Whether the ParseUser has been authenticated on this device. ParseUser是否已在此设备上进行了身份验证。 This will be true if the ParseUser was obtained via a logIn or signUp method. 如果ParseUser是通过logIn或signUp方法获得的,则为true。 Only an authenticated ParseUser can be saved (with altered attributes) and deleted. 只有经过身份验证的ParseUser可以保存(属性已更改)并删除。

getCurrentUser is always the user that has signed up or logged in. So if it is not null, the user is logged in. isAuthenticated is just to see if the user object was retrieved from a login/sign up or not. getCurrentUser始终是已注册或登录的用户。因此,如果它不为null,则表示该用户已登录isAuthenticated只是为了查看是否从登录/注册中检索到该用户对象。 For example, if you queried for other ParseUser objects, they would not be authenticated. 例如,如果您查询其他ParseUser对象,则将不对它们进行身份验证。

Also notice that when you do a logOut on the current user, getCurrentUser will be null. 还要注意,当您对当前用户进行logOut时, getCurrentUser将为null。

I also noticed that if you were not using the Local Datastore, currentUser.isAuthenticated() would always return true even when force closing the application. 我还注意到,如果您使用本地数据存储,则即使强制关闭应用程序, currentUser.isAuthenticated()也会始终返回true。

It seems that when you are using the Local Datastore, where the current user is retrieved locally, the object is no longer seen as "authenticated" as in the source is not from a login or sign up. 似乎当您使用本地数据存储时,在本地检索当前用户,该对象不再被视为“已认证”,因为源中不是来自登录或注册的对象。

Parse Android Changelog 解析Android Changelog

v1.5.1 — May 30, 2014 v1.5.1-2014年5月30日

Fixed various bugs with Local Datastore. 修复了本地数据存储区的各种错误。

The problem was indeed a Local Datastore bug which has been fixed today with the release of the new Parse Android SDK version 1.5.1. 问题确实是本地数据存储区错误,该错误已在今天通过新的Parse Android SDK版本1.5.1修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM