Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Update for latest Couchbase framework
Browse files Browse the repository at this point in the history
- Update class/method names for latest API
- Properly handle background/foreground transitions
  • Loading branch information
snej committed Sep 9, 2011
1 parent 18555b7 commit 907da71
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Classes/LocationsAppDelegate.h
Expand Up @@ -5,7 +5,7 @@
Version: 1.1 Version: 1.1
*/ */


#import <Couchbase/CouchbaseEmbeddedServer.h> #import <Couchbase/CouchbaseMobile.h>
@class RootViewController, CouchServer; @class RootViewController, CouchServer;


@interface LocationsAppDelegate : NSObject <UIApplicationDelegate, CouchbaseDelegate> { @interface LocationsAppDelegate : NSObject <UIApplicationDelegate, CouchbaseDelegate> {
Expand Down
49 changes: 28 additions & 21 deletions Classes/LocationsAppDelegate.m
Expand Up @@ -28,7 +28,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.rootViewController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; self.rootViewController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];


// Initialize CouchDB: // Initialize CouchDB:
CouchbaseEmbeddedServer* cb = [[CouchbaseEmbeddedServer alloc] init]; CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
cb.delegate = self; cb.delegate = self;
if (![cb start]) { if (![cb start]) {
// TODO: Report error // TODO: Report error
Expand All @@ -48,40 +48,47 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
} }


// This is the CouchbaseDelegate method called when the database starts up: // This is the CouchbaseDelegate method called when the database starts up:
-(void)couchbaseDidStart:(NSURL *)serverURL { -(void)couchbaseMobile:(CouchbaseMobile*)cb didStart:(NSURL *)serverURL {
if (!serverURL) {
// TODO: Report error
NSLog(@"OMG: Couchbase couldn't start! Exiting!");
exit(1); // Panic!
}

#ifdef DEBUG #ifdef DEBUG
NSLog(@"CouchDB is ready, go!"); gCouchLogLevel = 1; // Turn on some basic logging in CouchCocoa
gRESTLogLevel = kRESTLogRequestHeaders;
#endif #endif


self.server = [[[CouchServer alloc] initWithURL: serverURL] autorelease]; if (!self.server) {
CouchDatabase* database = [self.server databaseNamed: @"locations"]; // Do this the first time the server starts, i.e. not after a wake-from-bg:

self.server = [[[CouchServer alloc] initWithURL: serverURL] autorelease];
RESTOperation* op = [database create]; CouchDatabase* database = [self.server databaseNamed: @"locations"];
if (![op wait] && op.httpStatus != 412) { // 412 = Conflict; just means DB already exists
// TODO: Report error RESTOperation* op = [database create];
NSLog(@"OMG: Couldn't create database: %@", op.error); if (![op wait] && op.httpStatus != 412) { // 412 = Conflict; just means DB already exists
exit(1); // Panic! // 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 { - (void)applicationDidEnterBackground:(UIApplication *)application {
// Make sure all async operations complete before allowing the process to be suspended: // 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 { - (void)applicationWillTerminate:(UIApplication *)application {
// Make sure all async operations complete before quitting: // Make sure all async operations complete before quitting:
[RESTOperation wait: rootViewController.database.activeOperations]; [RESTOperation wait: self.server.activeOperations];
} }




Expand Down
4 changes: 4 additions & 0 deletions Locations.xcodeproj/project.pbxproj
Expand Up @@ -279,13 +279,15 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99; GCC_C_LANGUAGE_STANDARD = c99;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1"; GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = ""; GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0; IPHONEOS_DEPLOYMENT_TARGET = 4.0;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO; PREBINDING = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
WARNING_CFLAGS = "-Wall";
}; };
name = Debug; name = Debug;
}; };
Expand All @@ -295,12 +297,14 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99; GCC_C_LANGUAGE_STANDARD = c99;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = ""; GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0; IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PREBINDING = NO; PREBINDING = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
WARNING_CFLAGS = "-Wall";
}; };
name = Release; name = Release;
}; };
Expand Down

0 comments on commit 907da71

Please sign in to comment.