Reputation: 10602
This is a simple question, is there a Parse format for checking if the user is already logged in, in a different device?
I'm aware I can manually do this, updating objects, registering devices and using pointers etc etc, just wondering if there is a simple API workaround or an easier alternative someone has creatively utilized?
Upvotes: 1
Views: 231
Reputation: 3461
Yes there is. They announced sessions in the latest Facebook conference. You need a basic find or count query in Session
class:
var query = PFSession.query()!
query.findObjectsInBackgroundWithBlock{ (objects: [AnyObject]?, error: NSError?) -> Void in
if error != nil {
println(error!)
} else {
if let sessions = objects {
println(sessions)
}
}
}
Note that you don't need to add query.whereKey("user", equalTo: currentUser)
. Because the query will only return the sessions of the current user due to the ACL set on the session object. The session object is something like:
createdWith = {
action = signup;
authProvider = anonymous;
};
expiresAt = "2016-04-14 13:43:53 +0000";
installationId = "...";
restricted = 0;
sessionToken = "...";
user = "<PFUser: 0x7fc990681120, objectId: yoELURj4i8>";
Upvotes: 2