Custom Service does not have a user token

I am trying to run a custom service for an app. I am using backendless sdk 4.0.4 for iOS.

The access token is not set for my BackendlessUser.

When I finish a login the object has the property ‘user-token’ and it is set.

But when I try to access to it using [backendless.userService currentUser] the property is no longer there.

When I store the ‘user-token’ locally and make rest calls everything works fine, but when I try to call any of the backendless sdks they fail because they say there is no logged in user.

Hello Asher,
That’s weird because everything should be fine. I’ve just checked it.
This is my js method code:

getLoggedUserToken() {
throw new Error('User not logged in')
return this.request.context.userToken

That’s my Obj-C code:

- (IBAction)pressedLogin:(id)sender {
[backendless.userService login:@""
response:^(BackendlessUser *loggedUser) {
user = loggedUser;
NSLog(@"User logged in with token: %@", [user getUserToken]);
error:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
// user = [backendless.userService login:@"" password:@"111"];
// NSLog(@"User logged in with token: %@", [user getUserToken]);
- (IBAction)pressedGetToken:(id)sender {
BackendlessUser *currentUser = [backendless.userService currentUser];
NSLog(@"Current user token = %@", [currentUser getUserToken]);

NSLog(@"Current user token = %@", [GreetingsService.sharedInstance getLoggedUserToken]);

The results attached on the screenshot.

Regards, Olga

Screen Shot 2017-07-27 at 10.40.36.png

Alright I think I found the issue.

I created a new project and used the code you referenced above. It worked fine and I was able to sign in a user. I also signed in a user using FBSDKAccessToken.

The problem happened when I tried to make the user persist across app launches.
In my AppDelegate.m I call:

[backendless initApp:APP_ID APIKey:SECRET_KEY_IOS];
[backendless.userService setStayLoggedIn:YES];

And now whenever I try to login the system throws an exception:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[NSDictionary initWithDictionary:copyItems:]: dictionary argument is not an NSDictionary’

If I don’t call ‘setStayLoggedIn’ it works fine but as soon as I do it corrupts my iOS app, and when I remove the line and relaunch the app I still get the same issue. Even deleting the build off the simulator device doesn’t fix it. I have to create a new project to get it to work again.


After spending more time investigating I think my issue is with retrieving objects from the User Table. I Created a local class to represent the object but it looks like that is messing with the BackendlessUser class. I don’t see how but maybe there is a name overlap that is causing the program to act funny and as soon as I try to load an instance of a user everything goes crazy.


Creating a custom class to represent the objects from the Users table is not a good idea. There is a lot of logic within the SDK which is coupled to the BackendlessUser class and you should use that one instead.


Got it, I switched everything to the BackendlessUser and am calling the getProperty function and now it works as expected.

Thank you,

Hello Asher,

Can this topic be marked as solved?

Regards, Olga