On Dec 1, 2015, at 9:11 AM, Herman Chan <herm...@gmail.com> wrote:
I can see that [CBLDatabase createPullReplication] can return nil (mark nullable), when will that happen? Moreover, what should we do when that happens?
- (void) createDatabaseAndStartReplication:(NSArray*)groupIds {
NSError *__autoreleasing error;
for (NSString *groupId in groupIds) {
NSString *databaseName = [NSString stringWithFormat:@"group_%@", groupId];
CBLDatabase *database = [self.server databaseNamed:databaseName error:&error];
HubCredential *credInfo = [[HubCredentialService sharedInstance] credInfo];
NSString *url;
if ([HubUserDefaults hubEmbedUserPassInReplicateURL]) {
url = [NSString stringWithFormat:@"%@%@",REMOTE_COUCH_DB_URL, databaseName];
}
else {
url = [NSString stringWithFormat:@"%@%@",REMOTE_COUCH_DB_URL, databaseName];
}
CBLReplication *pullRepl = [database createPullReplication:[NSURL URLWithString:url]];
CBLReplication *pushRepl = [database createPushReplication:[NSURL URLWithString:url]];
pullRepl.authenticator = [CBLAuthenticator basicAuthenticatorWithName:credInfo.userName password:credInfo.password];
pushRepl.authenticator =[CBLAuthenticator basicAuthenticatorWithName:credInfo.userName password:credInfo.password];
[self addReplications:@[pullRepl, pushRepl]];
[self setupPushFilters:database];
}
}
- (void) addReplications: (NSArray*)replications {
for (CBLReplication* repl in replications) {
[self addReplication: repl];
}
}
- (void) addReplication: (CBLReplication*)repl {
if (![self.replications containsObject: repl]) {
repl.continuous = YES;
[self.replications addObject:repl];
if (repl.pull) {
[self.pullReplications addObject:repl];
}
[repl start];
/*listen to all properties of all replications*/
[repl addObserver:self forKeyPath:@"status" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:NULL];
}
}
Thread : Fatal Exception: NSInvalidArgumentException0 CoreFoundation 0x183558f48 __exceptionPreprocess1 libobjc.A.dylib 0x198a03f80 objc_exception_throw2 CoreFoundation 0x1834421ec -[__NSPlaceholderArray initWithObjects:count:]3 CoreFoundation 0x18344dc94 +[NSArray arrayWithObjects:count:]4 my123app 0x1001ceb74 -[HubTouchDBService createDatabaseAndStartReplication:] (HubTouchDBService.m:134)5 my123app 0x10016e060 __33-[Authorization signIn:password:]_block_invoke (Authorization.m:216)6 my123app 0x10062433c __84-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:success:failure:]_block_invoke74 (AFHTTPSessionManager.m:250)7 my123app 0x1006376fc __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_272 (AFURLSessionManager.m:194)8 libdispatch.dylib 0x1992156e8 _dispatch_call_block_and_release9 libdispatch.dylib 0x1992156a8 _dispatch_client_callout10 libdispatch.dylib 0x19921adb0 _dispatch_main_queue_callback_4CF11 CoreFoundation 0x1835101f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__12 CoreFoundation 0x18350e060 __CFRunLoopRun13 CoreFoundation 0x18343cca0 CFRunLoopRunSpecific14 GraphicsServices 0x18e9c0088 GSEventRunModal15 UIKit 0x188b54ffc UIApplicationMain16 simplyUs 0x1000af5a0 main (main.m:14)17 libdyld.dylib 0x1992468b8 start