@property (nonatomic, strong) CBLManager *manager;
@property (nonatomic, strong) dispatch_queue_t backgroundTaskQueue;
@property (nonatomic, strong) CBLManager *backgroundManager;
@property (nonatomic, strong) CBLDatabase *backgroundDatabase;
- (id)init {
self = [super init];
if (self) {
NSError *error;
_manager = [[CBLManager alloc] init];
if (!_manager) {
NSLog(@"Cannot create CBLManager");
return nil;
}
_database = [_manager databaseNamed:@"datastore" error:&error];
if (!_database) {
NSLog(@"Cannot create database. Error message: %@", error.localizedDescription);
return nil;
}
_backgroundTaskQueue = dispatch_queue_create("wapos.database.queue", DISPATCH_QUEUE_SERIAL);
_backgroundManager = [self.manager copy];
_backgroundManager.dispatchQueue = _backgroundTaskQueue;
[self setupBackgroundDatabase];
}
return self;
}
- (void)setupBackgroundDatabase {
@weakify(self);
NSString *databaseName = self.database.name;
dispatch_sync(_backgroundTaskQueue, ^{
@strongify(self);
NSError *error;
self.backgroundDatabase = [self.backgroundManager databaseNamed:databaseName error:&error];
});
}
dispatch_async(self.dbManager.backgroundTaskQueue, ^{
}
// Called in response to replication-change notifications.
- (void)replicationProgress: (NSNotification *)notification {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
CBLReplication *replication = (CBLReplication *)notification.object;
BOOL active = _pull.status == kCBLReplicationActive || _push.status == kCBLReplicationActive;
self.syncing = active;
if (active) {
} else {
[self setupBackgroundDatabase];
}
}
- (void)setupBackgroundDatabase {
@weakify(self);
NSString *databaseName = self.database.name;
dispatch_sync(_backgroundTaskQueue, ^{
@strongify(self);
NSError *error;
self.backgroundDatabase = [self.backgroundManager databaseNamed:databaseName error:&error];
[DBManager setupDatabase:self.backgroundDatabase];
});
}
On Jul 2, 2017, at 3:58 AM, Shen Kevin <vampi...@gmail.com> wrote:It seems that documents and views are not synchronized between two CBLDatabase instanceswhich share one database file.