Support Topics Documentation Slack YouTube Blog

Using hosted api/custom service with swift


(Juacall Bernard) #1

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?


(Anton Govorushkin) #2

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


(Juacall Bernard) #3

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


(Juacall Bernard) #4

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> )






(Anton Govorushkin) #5

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


(Juacall Bernard) #6

Yes I’ve attached some screenshots


(Anton Govorushkin) #7

Ok, thanks, Bernard

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

Regards Anton


(Juacall Bernard) #8

Have you found out anything?


(Mark Piller) #9

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


(Juacall Bernard) #10

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.


(Juacall Bernard) #11

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


(Mark Piller) #12

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.


(Juacall Bernard) #13

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> )


(Juacall Bernard) #14

Any new information?


(Mark Piller) #15

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.


(Juacall Bernard) #16

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


(Juacall Bernard) #17

Any luck?


(Mark Piller) #18

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

Regards,
Mark


(Olha Danylova) #19

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

Regards, Olga


(Juacall Bernard) #20

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