Yes, this would be extremely helpful!
Alex
Hi XMann,
Yes indeed. I'm (slowly) hacking away at the Phonegap/iOS combo
https://github.com/dch/couchgap and there are others working on
android too. Hopefully later this week I'll have sorted out passing
the couchbase URL/port combo back into phonegap so it can load that
rather than the current index.html. Suggestions and help welcomed as
I'm more couch than iOS.
Cheers
Dave
Cheers
Dave
--
Amos
Hi Amos,
I've been hacking away at this. However in both phonegap and couchbase
the code has changed & now what was quite messy is now an easy matter
of plugging the frameworks together. I'm not sure its even necessary
for my GH repo anymore.
I'm further on than last week but still not quite there - I'm learning
ObjC as I go here. Help welcomed!
________________________________________________________________________________
# Getting started with PhoneGap and Couchbase-iOS
Here's a quick start guide to getting your first PhoneGap app running with its
own local CouchDB included.
Phonegap provides leading-edge integration between smartphone native APIs
industry-standard Javascript. Couchbase provides leading-edge integration
between Apache CouchDB and smartphones such as Android and iOS-based devices.
Huge thanks to Couchbase, PhoneGap and the CouchDB community for enabling this
through open source.
________________________________________________________________________________
# Pre-requisites
## Get Xcode 4
You'll need this to compile Couchbase-iOS from source for your App.
## Get PhoneGap
- Close Xcode
- Download [Phonegap] 0.9.5.1 or get it from the [PhoneGap GitHub repo], and
run the template installer, accepting defaults:
unzip ~/Downloads/phonegap-0.9.5.1.zip
open phonegap-0.9.5.1/iOS/PhoneGapInstaller.pkg
## Couchbase
Marty Schoch's precompiled bundle is now up at [Couchbase Labs] on github!
- Get the Couchbase bits
git clone https://github.com/couchbaselabs/iOS-Couchbase-Templates
cd iOS-Couchbase-Templates/
open CouchbaseTemplates.xcworkspace/
Install the templates:
- Choose scheme `Download Couchbase` and run it - takes a while
- Choose scheme `Install Xcode Project Templates` & run it too
- Confirm couchbase files are now in `~/Library/Developer/Xcode/Templates/`
## Your App
- Create a new Xcode Workspace
- Create a new Xcode Project & select the new PhoneGap template
- Select scheme `iPhone Simulator` and run it once to initialise - it
should start, but the simulator will error _missing file
www/index.html_
- Open the project in Finder and drag the new `www/` folder into your
Supporting Files, add as reference
### Change build target
- Go to project view and select your PhoneGap target
- Select `Build Phases` & open `Link with Binaries`
- Select `+` and add in `libstdc++.dynlib`
### Import the Couchbase bits
- Open in Finder
`~/Library/Developer/Xcode/Templates/Couchbase/Couchbase\
Base.xctemplate`
- Drag `libCouchbase.a` into your project's `Frameworks` folder, add
as reference
- Drag `Couchbase.bundle` into `Supporting Files`, copy (so we can
edit bits of it later)
- Select the project target again, then select `Build Phases` tab
- In bottom right corner of Xcode, choose `Add Build Phase -> Add Copy
Headers -> Add Other`
- Select `Couchbase.h` from
`~/Library/Developer/Xcode/Templates/Couchbase/Couchbase
Base.xctemplate/` and add as reference
### Extend your App Delegate with Couchbase Magic
- In your `.h` file, import the Couchbase header file & protocols:
#import "Couchbase.h"
@property(nonatomic, retain)NSURL *couchbaseURL;
-(void)couchbaseDidStart:(NSURL *)serverURL;
-(NSURL *)getCouchbaseURL;
- In your `.m` file, add the `couchbaseDidStart` delegate callback:
@synthesize couchbaseURL;
-(NSURL *)getCouchbaseURL {
return self.couchbaseURL;
}
- (void)couchbaseDidStart:(NSURL *)serverURL {
self.couchbaseURL = serverURL;
NSLog(@"[INFO] CouchDB is ready at serverURL %@",serverURL);
}
### Get Couchbase to start when PhoneGap starts
- In your `.m` file, at the beginning of `application
didFinishLaunchingWithOptions`, add
[Couchbase startCouchbase:self];
- this should accept optional port/parameter according to
https://github.com/couchbaselabs/iOS-Couchbase/blob/master/Demo/Classes/DemoAppDelegate.m#L45
### Get the Couchbase URL and pass it to PhoneGap [TODO]
> On 2011-06-06, at 12:57 AM, J. Chris Anderson wrote:
>
>> I think what will happen is PhoneGap will implement the normal Couchbase callbacks, and then give you a phonegap window that is already pointed in the right place.
>
This was my intent; however:
- phonegap looks like its expecting to use file:/// all over the
place. this looks fixable but kinda messy; I have asked their list for
some ideas on passing the URL through
- this [1] suggests I should be able to call [[Couchbase
startCouchbase:self] and pass a known port. The source doesn't look
like that's a goer. Is it possible to fix the port?
Chris - any news of a wiki?
A+
Dave
[1]: https://github.com/couchbaselabs/iOS-Couchbase/blob/master/Demo/Classes/DemoAppDelegate.m#L45
That is a great write up and I will go with it so I'm in sync with what you are doing. I'm new to iOS too. Will the response on the Phonegap list help with that last bit? He does this:
I guess I will have to try building it to see what his demoapp.couch contains. I'm trying to understand what Phonegap needs with file:/// after the initial page load. If an app were to write out an index.html for Phonegap with an immediate redirect, would that break something?
Also, I assume the default of a random port is to avoid collisions between apps on the same device. If it selects a random port that is already in use, will it try again? I'm not sure that selecting a fixed port is wise in the long run.
--
Amos
Yeah it looks like it nails it, I'll work through rest of it today &
push it all to github. There are a few things I want to change; he
bundles a demoapp.couch in with the project & does the copy with
obj-c. I'd like to have the app start up in futon, and then couchapp
push away.
> https://github.com/alunny/ios-couch-phonegap-helloworld/blob/master/helloworld/Classes/AppDelegate.m#L125-132
>
> I guess I will have to try building it to see what his demoapp.couch contains. I'm trying to understand what Phonegap needs with file:/// after the initial page load. If an app were to write out an index.html for Phonegap with an immediate redirect, would that break something?
>
> Also, I assume the default of a random port is to avoid collisions between apps on the same device. If it selects a random port that is already in use, will it try again? I'm not sure that selecting a fixed port is wise in the long run.
Agreed, but it saves a lot of time for me when fiddling with couchdb
via couchapp & other tools.
A+
Dave
I had some time to try this out. I've included a few fixes/comments to your instructions inline.
--
Amos Hayes
Geomatics and Cartographic Research Centre
Carleton University, Canada
aha...@gcrc.carleton.ca
+1.613.520.2600x8179
On 2011-06-07, at 10:30 AM, Dave Cottlehuber wrote:
>
This scheme didn't exist. I had to add it.
> - Choose scheme `Install Xcode Project Templates` & run it too
> - Confirm couchbase files are now in `~/Library/Developer/Xcode/Templates/`
>
> ## Your App
>
> - Create a new Xcode Workspace
> - Create a new Xcode Project & select the new PhoneGap template
> - Select scheme `iPhone Simulator` and run it once to initialise - it
> should start, but the simulator will error _missing file
> www/index.html_
> - Open the project in Finder and drag the new `www/` folder into your
> Supporting Files, add as reference
>
> ### Change build target
>
> - Go to project view and select your PhoneGap target
> - Select `Build Phases` & open `Link with Binaries`
This should be "Link Binaries with Libraries"
But there are two in the list. The first has 13 frameworks already in there. The second has 0 items. I chose the former.
> - Select `+` and add in `libstdc++.dynlib`
That library shows up three times for me (all together). Does it matter which I pick? I chose the first match.
>
> ### Import the Couchbase bits
>
> - Open in Finder
> `~/Library/Developer/Xcode/Templates/Couchbase/Couchbase\
> Base.xctemplate`
> - Drag `libCouchbase.a` into your project's `Frameworks` folder, add
> as reference
> - Drag `Couchbase.bundle` into `Supporting Files`, copy (so we can
> edit bits of it later)
> - Select the project target again, then select `Build Phases` tab
> - In bottom right corner of Xcode, choose `Add Build Phase -> Add Copy
> Headers -> Add Other`
In bottom right corner of Xcode, choose `Add Build Phase -> Add Copy
Headers'
Then expand that build phase and click "+" in it to "Add Other..."
> - Select `Couchbase.h` from
> `~/Library/Developer/Xcode/Templates/Couchbase/Couchbase
> Base.xctemplate/` and add as reference
>
> ### Extend your App Delegate with Couchbase Magic
>
> - In your `.h` file, import the Couchbase header file & protocols:
>
> #import "Couchbase.h"
>
> @property(nonatomic, retain)NSURL *couchbaseURL;
> -(void)couchbaseDidStart:(NSURL *)serverURL;
> -(NSURL *)getCouchbaseURL;
>
> - In your `.m` file, add the `couchbaseDidStart` delegate callback:
>
> @synthesize couchbaseURL;
>
> -(NSURL *)getCouchbaseURL {
> return self.couchbaseURL;
> }
>
> - (void)couchbaseDidStart:(NSURL *)serverURL {
> self.couchbaseURL = serverURL;
> NSLog(@"[INFO] CouchDB is ready at serverURL %@",serverURL);
> }
>
>
> ### Get Couchbase to start when PhoneGap starts
>
> - In your `.m` file, at the beginning of `application
> didFinishLaunchingWithOptions`, add
>
> [Couchbase startCouchbase:self];
This gives the warning "Sending 'AppDelegate *' to parameter of incompatible type 'id<CouchbaseDelegate>'"
Building and running seems to work although there are some warnings reported:
Nunaliit
/Users/ahayes/Documents/Apps/Nunaliit/Nunaliit/Classes/AppDelegate.m
Class 'AppDelegate' does not implement the 'CouchbaseDelegate' protocol
file://localhost/Users/ahayes/Documents/Apps/Nunaliit/Nunaliit/Classes/AppDelegate.m: warning: Semantic Issue: Sending 'AppDelegate *' to parameter of incompatible type 'id<CouchbaseDelegate>'
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'Nunaliit/Nunaliit-Info.plist'.
Directory not found for option '-L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/gcc/arm-apple-darwin10/4.0.1'
warning: Missing - Add /Users/ahayes/Documents/Apps/Nunaliit/www as a folder reference in your project. Just drag and drop the folder into your project, in Xcode 4.
Jon.