Running a CouchApp in a hybrid iOS app

79 views
Skip to first unread message

Aaron Vegh

unread,
May 23, 2014, 11:50:34 PM5/23/14
to mobile-c...@googlegroups.com
Hi there!
I'm doing some initial research into deploying an iOS app using a CouchApp, serving its views into UIWebViews in a wrapper app of sorts. I note a brief mention of using PhoneGap for this purpose (http://docs.couchbase.com/couchbase-lite/cbl-concepts/#what-about-couchapps) but I'm leery of using PhoneGap, primarily because I want to leverage the same technology to create a Mac version of the same app. 

I've found jchris' project HelloTouchApp (https://github.com/jchris/HelloTouchApp), which appears to accomplish what I'm after, but it's quite out of date, and my attempts to leverage its fundamental workings have been unsuccessful. 

There's precious little discussion and documentation about this style of app, especially concerning iOS and Mac development. I'd be interested in knowing if this is possible, because it strikes me as an incredibly powerful architecture, especially for my intended use case.

Thanks,
Aaron

P.S. During my investigations I've also run into Kanso (kan.so) and Hoodie (hood.ie), both of which seem to offer some level of CouchApp, but they don't seem production-ready. If there are any other techniques out there, I'd love to hear about them.

Alexander Gabriel

unread,
May 24, 2014, 2:00:44 PM5/24/14
to mobile-c...@googlegroups.com

Yep, I'm interested too

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/3674bb46-4b65-4e4a-bde2-d21b1aaa55a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
May 24, 2014, 6:13:54 PM5/24/14
to mobile-c...@googlegroups.com

On May 23, 2014, at 8:50 PM, Aaron Vegh <aa...@vegh.ca> wrote:

I'm doing some initial research into deploying an iOS app using a CouchApp, serving its views into UIWebViews in a wrapper app of sorts. I note a brief mention of using PhoneGap for this purpose (http://docs.couchbase.com/couchbase-lite/cbl-concepts/#what-about-couchapps) but I'm leery of using PhoneGap, primarily because I want to leverage the same technology to create a Mac version of the same app. 

I would just go ahead and use PhoneGap; otherwise you’ll be reinventing most of what it does.
Even if you wrote your own UIKit wrapper code, it’s still iOS-only, so you’d still need to write new code for a Mac OS version.

—Jens

Aaron Vegh

unread,
May 24, 2014, 10:54:50 PM5/24/14
to mobile-c...@googlegroups.com
Hi Jens,

I would just go ahead and use PhoneGap; otherwise you’ll be reinventing most of what it does.
Even if you wrote your own UIKit wrapper code, it’s still iOS-only, so you’d still need to write new code for a Mac OS version. 

I'm sorry, your rationale appears to be contradictory: if I need to come up with a solution that works on the Mac anyway, why not figure one out that works on iOS too?

If PhoneGap offers the only way to do this now, I guess the question moves on to "how do they do it?" If this is the project you're talking about (https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin), there's surprisingly little code in that project, at the core of which is this method:

- (void)launchCouchbaseLite
{
    NSLog(@"Launching Couchbase Lite...");
    CBLManager* dbmgr = [CBLManager sharedInstance];
    CBLRegisterJSViewCompiler();
    self.liteURL = dbmgr.internalURL;
    NSLog(@"Couchbase Lite url = %@", self.liteURL);
}

In my own attempt I used the -internalURL method without success, but this CBLRegisterJSViewCompiler(), which digs into an included binary framework... and this is where I lose the trail at the moment. Is this path worth pursuing, do you think? Or is this a rabbit hole that leads to requiring PhoneGap, and I'm back to square one?

Cheers,
Aaron 

Jens Alfke

unread,
May 24, 2014, 11:31:21 PM5/24/14
to mobile-c...@googlegroups.com

On May 24, 2014, at 7:54 PM, Aaron Vegh <aa...@vegh.ca> wrote:

I'm sorry, your rationale appears to be contradictory: if I need to come up with a solution that works on the Mac anyway, why not figure one out that works on iOS too?

You can't, because AppKit and UIKit are different, and because WebView and UIWebView are very different. What you need is a shell for hosting a local web-app, and that shell is going to have to be custom-written for each platform. Or, on iOS you can use one that already exists (PhoneGap) which leaves you only one to write yourself.

Plugging CBL into that shell, once you have it, is pretty trivial. You just need to initialize it at launch time, which is what that code you quoted does.

In my own attempt I used the -internalURL method without success, but this CBLRegisterJSViewCompiler(), which digs into an included binary framework…

That framework is just a copy of Apple's JavaScriptCore for use on iOS 6, because it wasn’t made public till iOS 7.

and this is where I lose the trail at the moment. Is this path worth pursuing, do you think? Or is this a rabbit hole that leads to requiring PhoneGap, and I'm back to square one?

They’re orthogonal to each other. You need (a) a shell for running a local web-app in a WebView, and (b) code to initialize CBL. Of these, (b) is already provided for you, and (a) is provided for iOS in the form of PhoneGap.

—Jens

Aaron Vegh

unread,
May 24, 2014, 11:46:29 PM5/24/14
to mobile-c...@googlegroups.com
Thanks for the additional context, Jens. 

Regarding that shell, I just came across this project, which provides an embedded HTTP server for Mac and iOS. https://github.com/swisspol/GCDWebServer

Do you think this could be leveraged to provide that missing link?

A.

Sent from my iPad
--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/3PLm_V-LMy8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/6CDF78DA-6A2D-4142-8A9E-948D2AF0124C%40couchbase.com.

J. Chris Anderson

unread,
May 25, 2014, 9:36:08 AM5/25/14
to mobile-c...@googlegroups.com
Perhaps this Mac PhoneGap container is relevant?

https://github.com/apache/cordova-osx

It's not the only way to do it (and our plugin isn't set up for this yet) but it might save you some work.

There are other Mac web containers that are probably equally easy / popular. Definitely no reason to do the heavy lifting your self.

Chris

Jens Alfke

unread,
May 25, 2014, 12:32:10 PM5/25/14
to mobile-c...@googlegroups.com

On May 24, 2014, at 8:46 PM, Aaron Vegh <aa...@vegh.ca> wrote:

Regarding that shell, I just came across this project, which provides an embedded HTTP server for Mac and iOS. https://github.com/swisspol/GCDWebServer

There’s already an HTTP server in the CouchbaseLiteListener framework.
I really think you’re making this out to be a bigger job than it actually is!
I see Chris just pointed out a PhoneGap-for-Mac container; that should solve the rest of your problem.

Anyway, the next issue you’re likely to run into in porting a CouchApp is that CBL has no support for list or show functions. Patches are welcome :)

—Jens
Reply all
Reply to author
Forward
0 new messages