I have a case where some a custom service/Business Logic code is running and updating user properties on the Users data table. I’d like this service to return a ‘BackendlessUser’ object in response. I am able to invoke the service, take the response and cast the value ‘properties’ field to a BackendlessUser ok. (this seems to work fine - please indicate if you believe this to be a problem)
How can I set the ‘currentUser’ property then in the UserService? On android there seems to be a ‘setCurrentUser’ method which allows one to set the user without having to login. I cannot see a way to do this on iOS.
I realize that I can just refresh/fetch the user again through the UserService- but I was attempting to reduce the number of server calls (among other things)
//bump
Hi Joey,
I apologize for missing your question. Just to clarify the use-case, is the intent to set the current user on a device in order to force all subsequent API calls to be executed using the user’s identity?
Regards,
Mark
Well I don’t need to change the session/user identity information to another user entirely (I understand that is weird case) - merely kind of update the user record with properties/changes that were made as a result of the API call. The result will technically be the same user as was logged in previously - just with new/updated properties. I realized I could just get/set on the existing user - but being able to swap out whole seems slightly more elegant and is the same as what we are doing on the Android side (where this method/ability exists).
Again - I can likely code around this if you don’t think this should be possible - was just pointing out disparity in API availability
I will create a ticket to allow adding a “bag of properties” to an existing user object in iOS. This will let you do exactly what you want.
hrm - I guess it would kind of work if there was a way to get a “bag of properties” from an existing data object/user instance (being all the custom properties) - not sure that method exists currently. Otherwise you’d be wasting your time as I’d just get/set when I was specifically.
I know you can do it in Java, I am not sure about iOS. I will find out and let you know.
Hi Joey,
- Added BackendlessUser addProperties() method.
- A casting conflict [AnyObject] <> NSMutableObjects has been fixed, so now this swift example works:
func mergeUserProperties() {
Types.tryblock({ () -> Void in
// login user
let firstUser = self.backendless.userService.login(“test@backendless.com”, password: “test”)
print(“User has been logged in: (firstUser)”)
// retrieve some other user
let secondUser = self.backendless.data.of( BackendlessUser.ofClass() ).findFirst()
print(“User has been find: (secondUser)”)
// merge the properties of both users - add the props of the 2nd to the one who is logged in
firstUser.addProperties( secondUser.getProperties() )
print(“User’s properties have been merged: (firstUser)”)
},
catchblock: { (exception) -> Void in
print(“Server reported an error: (exception as! Fault)”)
}
)
}
You can download the fixed lib files:
https://github.com/Backendless/ios-SDK/blob/master/SDK/lib/backendless/backendless.a
https://github.com/Backendless/ios-SDK/blob/master/SDK/lib/backendless/include/BackendlessUser.h