Using hosted api/custom service with swift

I’ve added the backendless sdk to my project and have intialized by using

 backendless?.hostURL = BACKENDLESS_HOST
backendless?.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)

I downloaded the objective c hosted api and added the files to my project. I imported them in my bridged header. When i try to use my custom service i receive app id or secret are incorrect. So i attempted to use a work around by using invoke custom service.

let array: NSArray = [newUser, responseBlock, errorblock]
self.appDelegate.backendless?.customService.invoke(self.appDelegate.SERVICE_NAME, serviceVersion: self.appDelegate.SERVICE_VERSION_NAME, method: "postUser", args: array as! [Any])

I get the same error app id or secret are incorrect. I’ve tried using curl with rest to test the app id and secret and that works but through code i receive errors and rest with custom objects is either not possible or way to troublesome to consider. There are 0 samples showing how to use a hosted service unless I’m just not good at looking. Can you tell me why I’m receiving such errors or point in the direction of something that would help me?

Bernard, I assume you are using version 3 of Backendless? If so - please provide your application id and name of the service you are trying to invoke.

Regards Anton

Yes i’m using version 3. The name of the custom service is EpilepsyService
My app id is
CE6DAFE1-FEAB-9A8E-FFA9-BA98F212A300

When i use customservice.invoke i recieve the error




FAULT = '14019' [Service Version not found] <Service Version not found> )FAULT = '14019' [Service Version not found] <Service Version not found> )





Can you please share the exact service version your are passing in the invocation request? Also can you verify that it corresponds to the actual version of your service?

Regards Anton

Yes I’ve attached some screenshots

Ok, thanks, Bernard

I’ll dig into it and get back to you in a while with results.

Regards Anton

Have you found out anything?

Hello,

I am looking at your service and the code you posted and do not see the “postUser” method. The service declares only two methods: “getUser” and “getRefDisorderTypes”.

I agree, there are no shown samples in the doc, however, the code client SDK code you download for the service shows how each method can be invoked. I understand the downloaded code is for Objective-C and you develop in Swift. We have improved it in version 4 of Backendless.

Regards,
Mark

Unfortunately you must be looking at the wrong service because i’m using the same service for android and everything works fine. I know how to invoke each method its just that i get an error when i try to use it correctly. I try to use the service directly like in android and i get an error saying the app id or secret is wrong. I try to go around by use your invoke command and i get the version number is wrong.

The service named neurish that only has those two that you mentioned but EpilepsyService has many more

Sorry, I was indeed looking at the wrong service.

Here’s what the generated objective-c code looks like for that method:

-(void)postUser:(BackendlessUser *)user response:(void(^)(BackendlessUser *))responseBlock error:(void(^)(Fault *))errorBlock {
 [backendless.customService invoke:SERVICE_NAME serviceVersion:SERVICE_VERSION_NAME method:@"postUser" args:@[user] response:responseBlock error:errorBlock];
}

Notice that blocks are not passed into the args array, only the user object goes in there. I think that’s the main difference between your Swift code and this obj-c code. Try taking out the blocks from the args array and see if the method can be invoked then.

let args: NSArray = [newUser]





            

            

            

            self.appDelegate.backendless?.customService.invoke(self.appDelegate.SERVICE_NAME, serviceVersion: self.appDelegate.SERVICE_VERSION_NUMBER, method: "postUser", args: args as! [Any])


Same error

‘14019’ [Service Version not found] <Service Version not found> )

Any new information?

Sorry, missed your reply you sent earlier. What version of the SDK do you use? We’d like to try replicating the problem on our end.

We are using pod so i assume the most recent version. In the readme it has 3.0.43:

Any luck?

Not yet. A ticket was assigned to a developer. We will post an update as soon as we check.

Regards,
Mark

Hello Bernard,
The latest iOS-SDK of 3.x version is 3.0.46. Please, update and check - everything should be fine.

Regards, Olga

When i run pod update it updated to 3.0.44 and i still receive the same error.