Backendless Support
 
Answered

Using hosted api/custom service with swift

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

  1. backendless?.hostURL = BACKENDLESS_HOST
  2. 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.

  1. let array: NSArray = [newUser, responseBlock, errorblock]
  2. 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?

Leave a Comment

Comments (28)

photo
1

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

photo
1

Yes i'm using version 3. The name of the custom service is EpilepsyService

My app id is

CE6DAFE1-FEAB-9A8E-FFA9-BA98F212A300

photo
1

When i use customservice.invoke i recieve the error

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

photo
1

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

photo
1

Ok, thanks, Bernard

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

Regards Anton

photo
1

Have you found out anything?

photo
1

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

photo
1

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.

photo
1

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

photo
1

Sorry, I was indeed looking at the wrong service.

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

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

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.

photo
1

let args: NSArray = [newUser]

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

photo
photo
1

Any new information?

photo
1

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.

photo
1

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

photo
1

Any luck?

photo
1

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

Regards,

Mark

photo
photo
1

Hello Bernard,

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

Regards, Olga

photo
1

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

photo
1

I figured it out but i get a diffrent error now,

<Version is disabled or provided wrong application info (application id or secret key)>

photo
1

Please make sure your pod command in the podfile looks like

  1. pod 'Backendless', '~> 3.0'

and it should install v3.0.46

  1. Analyzing dependencies
  2. Downloading dependencies
  3. Installing Backendless (3.0.46)
  4. Generating Pods project
  5. Integrating client project
  6. Sending stats
  7. Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

photo
1

  1. Analyzing dependencies

    Downloading dependencies

    Using Backendless (3.0.46)

    Generating Pods project

    Integrating client project

    Sending stats

    Pod installation complete! There is 1 dependency from the Podfile and 1 total

    pod installed.

I just get a diffrent error now

photo
1

So you updated to 3.0.46 and now getting a 'Version is disabled' error message?

If so, please provide your code which does the initApp call.

photo
1

  1. let BACKENDLESS_HOST = "https://api.backendless.com";;

    let SERVICE_NAME = "EpilepsyService";

    let SERVICE_VERSION_NUMBER = "1.0.0";

    let APP_VERSION = "dev";

    let APP_ID = "CE6DAFE1-FEAB-9A8E-FFA9-BA98F212A300"//CE6DAFE1-FEAB-9A8E-FFA9-BA98F212A300

    let SECRET_KEY = "REMOVED FOR POST"

    let VERSION_NUM = "v1"

    var backendless = Backendless.sharedInstance()

  2. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    backendless?.hostURL = BACKENDLESS_HOST

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

    // If you plan to use Backendless Media Service, uncomment the following line (iOS ONLY!)

    // backendless.mediaService = MediaService()

    return true

    }

photo
1

You use version 'v1' while your app doesn't have such.

photo
1

when i download the custom sdk it comes with a sample that has that. If you know what's suppose to go there then can you let me know

photo
1

Depending on the version of your application you want to use, you'll need to have one of the following:

  1. let VERSION_NUM = "dev"

or

  1. let VERSION_NUM = "pre"

or

  1. let VERSION_NUM = "prod"

photo
photo
1

Everything works now