Support Topics Documentation Slack YouTube Blog

Custom Business Logic invoke by iOS always fails

Hi,

today I was trying to port my services from Backendless 3 to Backendless 4. Unfortunately I cannot make them works when called by the iOS app.
When I try to call them through the debug console all work fine.

Here are the two services basic implementation in the Java code deployed into the BE:

public String sayHello(String name) {
    return "Hello " + name;
}

and the second one:

public boolean addDiscoteca(Discoteca discoteca) {


    Discoteca discotecaFromDB = getDiscotecaWithFacebookId(discoteca.getFacebookId());


    if (discotecaFromDB == null) {
        Backendless.Persistence.of(Discoteca.class).save(discoteca);
    }


    return discotecaFromDB == null;
}

And here’s how I invoke these services in my app:



let name: String = "Matteo"
        
backendless?.customService.invoke("DiscotecaServices", serviceVersion: "0.0.0__debug", method: "sayHello", args: [name], response: { result in
    completion?(nil)
}, error: { fault in
    completion?(fault)
})
let discoteca = Discoteca()
discoteca.name = "Fabric"
        
backendless?.customService.invoke("DiscotecaServices", serviceVersion: "0.0.0__debug", method: "addDiscoteca", args: [discoteca], response: { result in
    completion?(nil)
}, error: { fault in
     completion?(fault)
})

For the sayHello service I received this error message:

\'Server.Processing\' [java.lang.ClassCastException@6afe0992] <java.lang.ClassCastException@6afe0992> )

For the addDiscoteca service I received this one:

\'Server.Processing\' [java.lang.ClassCastException@5070840b] <java.lang.ClassCastException@5070840b> 

For both the services CodeRunner doesn’t starts because these exceptions are raised before the Java methods take place.
Where am I wrong?

Hi Matteo,

if a service is deployed to Backendless, then the version number of the service should not have the “__debug” notation. It is valid only for services which run in the debug mode on the developer’s machine.

Or did you mean to say that the services are actually running in the debug mode?

Another question is are you using the 4.0 build of the iOS library?

And finally, does the invocation of the service work from a Java client?

Regards,
Mark

Hi Mark,

yes, the two services at this moment run in the debug mode on my machine.

In my app I’ve included the last Backendless SDK version using Cocoapods (pod ‘Backendless’, ‘4.0b3’).

And the the last point, sorry but I’m not able to test them with a Java client.

Thanks,
Matteo

Matteo,

An engineer will verify it and report back.

For tracking purposes an internal ticket is BKNDLSS-14459

Regards,
Mark

Thanks Mark, so I wait for the engineer report. The ticket status will be updated here?

Hi,
I update the question with further details.
Today I get a successful response from the service using the REST APIs in my iOS App with this sample code:

let url = "https://api.backendless.com/APP_ID/REST_API_KEY/services/DiscotecaServices/1.0.0/sayHello"
        
let header = [ "Content-Type": "application/json",
                       "Accept": "application/json"]
let body = "\"Matteo\""
        
let request = urlRequestWithRawBody(url, rawBody: body, header: header)
Alamofire.request(request).validate(statusCode: 200..<600).responseJSON { (response) in
                switch response.result {
                case .success:
                    if let JSON = response.result.value {
                        print("JSON: \(JSON)")
                    }
                case .failure( _):
                    break
                }
 }

Instead, using directly the iOS SDK with the invoke method, it still not works.
Hope this will help your investigation.

Matteo

Hi Matteo,

We identified a few problem areas in the code and fixed them in the upcoming release (4.0b8).

REST invocations do work though (as you have already determined).

Regards,
Mark

This sounds great!

Thanks for your work!

Matteo

Hi Matteo,

Can you please try again now?

HI Sergey,

I confirmed that now all works fine.

Thanks for the support, your service is awesome!
Matteo