使用 Parse iOS sdk 如何检索当前用户的会话 class

Using the Parse iOS sdk how do I retrieve the session class for the current user

我正在使用 Parse iOS SDK,并且我有兴趣向会话 class 添加一些额外的字段。我该如何去检索会话。我试过只根据当前用户进行查询,但它似乎永远都行不通。

        PFQuery *sessionQuery = [PFQuery queryWithClassName:@"Session"];
        //[sessionQuery whereKey:@"user" equalTo:currentuser];

        [sessionQuery getFirstObjectInBackgroundWithBlock:^(PFObject *session, NSError *error) {
            // comments now contains the comments for myPost
            if (!session) {
                NSLog(@"Could not find a session metching your parameters");
                NSLog(@"Error %@", error);
            }
            else
            {
                NSLog(@"Found the session bound to this user%@", session);
            }
        }]; 

您不需要查询它,可以使用以下

直接在iOS中访问它
PFUser.currentUser()?.sessionToken

关于会话令牌的一些重要注意事项from the documentation

PFSession objects can only be accessed by the user specified in the user field. All PFSession objects have an ACL that is read and write by that user only. You cannot change this ACL. This means querying for sessions will only return objects that match the current logged-in user.

换句话说,查询会话只有在您计划允许用户查看他们的所有会话并单独撤销它们时才有用,as mentioned in this blog post

  • Find, Delete — Useful for building a UI screen that allows users to see their active session on all devices, and log out of sessions on other devices. If your app does not have this feature, you should disable these permissions.

  • Get, Update, Add Field — Unless you need these operations, you should disable these permissions.

我很好奇您想在会话对象中存储哪些信息比在安装或用户对象中更有意义。希望这对您有所帮助!