Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mz2/syncpoint-ios
Syncpoint client library for iOS and Mac OS, including TouchDB and CouchCocoa
https://github.com/mz2/syncpoint-ios
Last synced: 25 days ago
JSON representation
Syncpoint client library for iOS and Mac OS, including TouchDB and CouchCocoa
- Host: GitHub
- URL: https://github.com/mz2/syncpoint-ios
- Owner: mz2
- Created: 2012-09-29T07:20:07.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-29T11:11:56.000Z (about 12 years ago)
- Last Synced: 2024-10-19T23:23:48.773Z (28 days ago)
- Language: Objective-C
- Homepage:
- Size: 662 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Syncpoint iOS Client
This driver includes building TouchDB and CouchCocoa to make and all in one sync engine that connects with Couchbase Syncpoint to do higher level APIs like sharing and channels.
In your `~/code` directory:
git clone --recursive git://github.com/couchbaselabs/Syncpoint-iOS.git
cd Syncpoint-iOS
open Syncpoint.xcworkspaceAnd **XCode** will come up and you'll be staring at some Objective-C.
## Setup the client with your Syncpoint URL
Please direct your attention to the `Syncpoint/Demo-iOS/DemoAppDelegate.m`, where we setup `SyncpointClient` with our remote URL, and then ask it for a CouchCocoa `CouchDatabase` using the `databaseForChannelNamed` call.
Here is the code with error handling.
```Objective-C
// needs a comment
NSLog(@"Setting up Syncpoint...");
NSURL* remoteURL = [NSURL URLWithString: kServerURLString];
NSError* error;
self.syncpoint = [[SyncpointClient alloc]
initWithRemoteServer: remoteURL
appId: kSyncpointAppId
error: &error];
if (error) {
[self showAlert: @"Syncpoint failed to start."
error: error fatal: YES];
return YES;
}
self.database = [syncpoint databaseForChannelNamed: @"grocery-sync"
error: &error];
if (!self.database) {
NSLog(@"error <%@>", error);
[self showAlert: @"Couldn't create local channel."
error: error fatal: YES];
return YES;
}
database.tracksChanges = YES;
NSLog(@"...using CouchDatabase at <%@>", self.database.URL);
// Tell the RootViewController:
RootViewController* root =
(RootViewController*)navigationController.topViewController;
[root useDatabase: database];
```That is the code that instantiates Syncpoint. The code that triggers paring with the cloud is in `/Syncpoint/Demo-iOS/ConfigViewController.m`
So that's how you tie your app to a Syncpoint instance in the cloud. With decent error handling, even.
## JSON Data API
You might be wondering how you do data stuff with Syncpoint. This is really more of a CouchCocoa question.
Here is an example of how we save a document (we use the (onCompletion handler to asynchronously respond to query)):
```Objective-C
// create the new document properties
NSDictionary* docData = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], @"check"
text, @"text",
nil];
// save the document
CouchDocument* doc = [database untitledDocument];
RESTOperation *op = [doc putProperties: docData];
// asynchronous handler
[op onCompletion: ^{
if (op.error) {
NSLog(@"REST error %@", op.dump);
}
// do your thing
[self savedDocument: doc];
}]
[op start];
```## Contribute:
We are active on the mailing list here: https://groups.google.com/forum/#!forum/mobile-couchbase
License is Apache 2.0.