Browse files

Update for latest Couchbase framework

- Update class/method names for latest API
- Properly handle background/foreground transitions
  • Loading branch information...
1 parent 18555b7 commit 907da71847e4ffc2ce7d294b5baa0f5edc527209 @snej snej committed Sep 9, 2011
Showing with 33 additions and 22 deletions.
  1. +1 −1 Classes/LocationsAppDelegate.h
  2. +28 −21 Classes/LocationsAppDelegate.m
  3. +4 −0 Locations.xcodeproj/project.pbxproj
View
2 Classes/LocationsAppDelegate.h
@@ -5,7 +5,7 @@
Version: 1.1
*/
-#import <Couchbase/CouchbaseEmbeddedServer.h>
+#import <Couchbase/CouchbaseMobile.h>
@class RootViewController, CouchServer;
@interface LocationsAppDelegate : NSObject <UIApplicationDelegate, CouchbaseDelegate> {
View
49 Classes/LocationsAppDelegate.m
@@ -28,7 +28,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.rootViewController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
// Initialize CouchDB:
- CouchbaseEmbeddedServer* cb = [[CouchbaseEmbeddedServer alloc] init];
+ CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
cb.delegate = self;
if (![cb start]) {
// TODO: Report error
@@ -48,40 +48,47 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
// This is the CouchbaseDelegate method called when the database starts up:
--(void)couchbaseDidStart:(NSURL *)serverURL {
- if (!serverURL) {
- // TODO: Report error
- NSLog(@"OMG: Couchbase couldn't start! Exiting!");
- exit(1); // Panic!
- }
-
+-(void)couchbaseMobile:(CouchbaseMobile*)cb didStart:(NSURL *)serverURL {
#ifdef DEBUG
- NSLog(@"CouchDB is ready, go!");
- gRESTLogLevel = kRESTLogRequestHeaders;
+ gCouchLogLevel = 1; // Turn on some basic logging in CouchCocoa
#endif
- self.server = [[[CouchServer alloc] initWithURL: serverURL] autorelease];
- CouchDatabase* database = [self.server databaseNamed: @"locations"];
-
- RESTOperation* op = [database create];
- if (![op wait] && op.httpStatus != 412) { // 412 = Conflict; just means DB already exists
- // TODO: Report error
- NSLog(@"OMG: Couldn't create database: %@", op.error);
- exit(1); // Panic!
+ if (!self.server) {
+ // Do this the first time the server starts, i.e. not after a wake-from-bg:
+ self.server = [[[CouchServer alloc] initWithURL: serverURL] autorelease];
+ CouchDatabase* database = [self.server databaseNamed: @"locations"];
+
+ RESTOperation* op = [database create];
+ if (![op wait] && op.httpStatus != 412) { // 412 = Conflict; just means DB already exists
+ // TODO: Report error
+ NSLog(@"OMG: Couldn't create database: %@", op.error);
+ exit(1); // Panic!
+ }
+ rootViewController.database = database;
}
- rootViewController.database = database;
+
+ rootViewController.database.tracksChanges = YES;
+}
+
+
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase failedToStart:(NSError*)error {
+ // TODO: Report error
+ NSLog(@"OMG: Couchbase couldn't start! Exiting!");
+ exit(1); // Panic!
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Make sure all async operations complete before allowing the process to be suspended:
- [RESTOperation wait: rootViewController.database.activeOperations];
+ [RESTOperation wait: self.server.activeOperations];
+ // Stop the change tracker until wake-up
+ rootViewController.database.tracksChanges = NO;
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Make sure all async operations complete before quitting:
- [RESTOperation wait: rootViewController.database.activeOperations];
+ [RESTOperation wait: self.server.activeOperations];
}
View
4 Locations.xcodeproj/project.pbxproj
@@ -279,13 +279,15 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = iphoneos;
+ WARNING_CFLAGS = "-Wall";
};
name = Debug;
};
@@ -295,12 +297,14 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PREBINDING = NO;
SDKROOT = iphoneos;
+ WARNING_CFLAGS = "-Wall";
};
name = Release;
};

0 comments on commit 907da71

Please sign in to comment.