Created
June 21, 2012 15:41
-
-
Save pulkitsinghal/2966533 to your computer and use it in GitHub Desktop.
AuthN is not really being used by TouchDB, you just think it is, fix this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma mark - SYNC Methods for TouchDB & IrisCouch | |
| - (void) updateSyncURL | |
| { | |
| if (!self.database) { | |
| return; | |
| } | |
| NSURL* remoteURL = [NSURL URLWithString:@"https://mydomain.iriscouch.com/mydb"]; | |
| NSArray* repls = [self.database replicateWithURL:remoteURL exclusively:YES]; | |
| _pull = [repls objectAtIndex: 0]; | |
| _push = [repls objectAtIndex: 1]; | |
| [_pull addObserver: self forKeyPath: @"completed" options: 0 context: NULL]; | |
| [_push addObserver: self forKeyPath: @"completed" options: 0 context: NULL]; | |
| } | |
| ... | |
| - (void) setupTouchDB | |
| { | |
| // 1) To sync successfully with a remote database that requires | |
| // authentication, your app will need to register credentials ahead of time | |
| NSURLCredential* cred; | |
| cred = [NSURLCredential credentialWithUser: @"_adminTypeUser" | |
| password: @"secret" | |
| persistence: NSURLCredentialPersistencePermanent]; | |
| NSURLProtectionSpace* space = | |
| [[NSURLProtectionSpace alloc] initWithHost: @"mydomain.iriscouch.com" | |
| port: 443 | |
| protocol: @"https" | |
| realm: @"some_realm" | |
| authenticationMethod: NSURLAuthenticationMethodDefault]; | |
| [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: cred | |
| forProtectionSpace: space]; | |
| // gRESTLogLevel = kRESTLogRequestHeaders; | |
| gCouchLogLevel = 1; | |
| // 2) Initialize TouchDB | |
| CouchTouchDBServer* server = [CouchTouchDBServer sharedInstance]; | |
| NSAssert(!server.error, @"Error initializing TouchDB: %@", server.error); | |
| // 3) Create the database on the first run of the app. | |
| NSLog(@"Creating database..."); | |
| self.database = [server databaseNamed: @"mydb"]; | |
| NSError* error; | |
| if (![self.database ensureCreated: &error]) { | |
| [self showAlert: @"Couldn't create a local database." error: error fatal: YES]; | |
| //return YES; | |
| } | |
| self.database.tracksChanges = YES; | |
| NSLog(@"...Created CouchDatabase at <%@>", self.database.URL); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment