Accessing rest api in IOS


#1

Just getting started with an IOS app containing CBL. It seems to be starting up ok, but when I hit the CBL internal url (http://lite.couchbase./) I just a network error. Here’s the code I’m using the launch the app:

CBLManager* dbmgr = [CBLManager sharedInstance];
CBLRegisterJSViewCompiler();
NSLog(@"Couchbase Lite url = %@", dbmgr.internalURL);

What have I missed?


#2

Do you need to use the REST API in this app? Usually people using that API are building PhoneGap apps, but it looks like you’re using native code, in which case the native API is the right choice.

Anyway, if you’re getting an error, it’s always a good idea to post the details of the error. :confused:


#3

It’s a react-native app. I’m using the javascript fetch api to access the CBL rest api. The error is just a network connection error, there are no details to speak of.

If I try using XmlHttpRequest the error is:

A server with the specified hostname could not be found.


#4

It sounds like React Native’s networking isn’t seeing the custom NSURLProtocol that CBL registers to handle the REST API. I don’t know anything about how React Native is implemented. There are two possibilities:

  1. They use NSURLSession, but are creating their own instance instead of using the default session. In that case our protocol handler will have to be registered in their session somehow.
  2. They use lower-level socket APIs and do all the HTTP client work themselves. They might do this if they want as much as possible of their code to be cross-platform. In that case CBL won’t be able to hook in.

You should file an issue with CBL-iOS about this.


#5

Thanks for the reply Jens. I don’t know enough about Ios programming to understand whats going on here. Think I’m going to have to work around it by using the CBLListener and actively stop/start it as the app changes state.


#6

Is this a Couchbase Lite plugin for React Native that you’re developing yourself? Or are you using one that someone else has developed?


#7

I’m helping develop this one: https://github.com/couchbaselabs/react-native-couchbase-lite