Backendless Support
 
Solved

iOS aSync loadRelations function does not go in response callback

When calling the aSync version of the loadRelations function, it does not go in the response callback.

Using the Sync version of the function works.

Am I doing something wrong? In the example below, the response is never called.

  1. let query = LoadRelationsQueryBuilder()
  2. query.setRelationName("subscriptions")

  3. ClientManager.backendless.data.of(BackendlessUser.ofClass()).loadRelations("FF92D849-4324-8601-FFAA-3B2A9ADC8E00", queryBuilder: query, response: {(items: [Any]?) -> Void in

    print(items!)

    }) { (fault) in

    print(fault!)

    }

Leave a Comment

Comments (10)

photo
1

Is the fault callback invoked? Any errors or warnings when the code makes the call?

photo
1

Nothing. it just steps over it.

photo
1

Have you tried setting breakpoints in the response/error blocks?

photo
1

Yes. It does not break

photo
1

What is your app id?

photo
1

B7F833A2-7B82-DECF-FF25-3555BC74F600

photo
1

I connected to your app and put together a quick test. Here's the complete code, it works just fine. Please try it in your project:

class ViewController: UIViewController {

let APPLICATION_ID = "YOUR-APP-ID"

let API_KEY = "YOUR-IOS-API-KEY"

let SERVER_URL = "https://api.backendless.com";

let backendless = Backendless.sharedInstance()!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

backendless.hostURL = SERVER_URL

backendless.initApp(APPLICATION_ID, apiKey: API_KEY)

let query = LoadRelationsQueryBuilder()

query.setRelationName("subscriptions")

backendless.data.of(BackendlessUser.ofClass()).loadRelations("FF92D849-4324-8601-FFAA-3B2A9ADC8E00", queryBuilder: query, response: {(items: [Any]?) -> Void in

print(items!)

}, error: { (fault) in

print(fault!)

})

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

photo
1

I am using the latest version of our SDK, which is 4.0.13

photo
1

Weird. It works if I try it in the ViewDidLoad function. I run this inside an object's constructor. Async call don't work in constructor?

photo
1

Yeah, it does not make sense to call an async API from a constructor. The behavior is non-deterministic. What if the call fails? Should it prevent the object from being created? I recommend refactoring your code to avoid an async call from a constructor.

photo