#pragma mark - Replication
- (void)startReplicator:(NSString *)username password:(NSString *)password {
// if (!kSyncEnabled)
// return;
CBLURLEndpoint *target = [[CBLURLEndpoint alloc] initWithURL:[NSURL URLWithString:@“ws://localhost:4094”]];
CBLReplicatorConfiguration *config = [[CBLReplicatorConfiguration alloc] initWithDatabase:_database target:target];
config.continuous = YES;
config.authenticator = [[CBLBasicAuthenticator alloc] initWithUsername:username password:password];
_replicator = [[CBLReplicator alloc] initWithConfig:config];
__weak typeof(self) wSelf = self;
[_replicator addChangeListener:^(CBLReplicatorChange *change) {
CBLReplicatorStatus *s = change.status;
NSError *e = s.error;
NSLog(@"[Todo] Replicator: %@ %llu/%llu, error: %@",
[wSelf ativityLevel: s.activity], s.progress.completed, s.progress.total, e);
[UIApplication.sharedApplication setNetworkActivityIndicatorVisible: s.activity == kCBLReplicatorBusy];
if (e.code == 401) {
[CBLUi showMessageOn:wSelf.window.rootViewController
title:@“Authentication Error”
message:@“Your username or passpword is not correct.”
error:nil
onClose:^{
[wSelf logout];
}];
}
}];
[_replicator start];