试用示例 couchbase lite 示例应用程序,它运行良好,直到我通过点击主页按钮将应用程序置于后台。当我返回应用程序并进入前台时,同步停止工作并且 nsnotifications 停止触发。让 couchbase lite 在再次进入前台时继续同步的最佳方法是什么?为什么它首先停止接收这些通知?
这是示例。
https://github.com/couchbaselabs/Grocery-Sync-iOS
- (void)updateSyncURL {
...
// Tell the database to use this URL for bidirectional sync.
// This call returns an array of the pull and push replication objects:
NSArray* repls = [self.database replicateWithURL: newRemoteURL exclusively: YES];
if (repls) {
_pull = repls[0];
_push = repls[1];
_pull.continuous = _push.continuous = YES;
// Observe replication progress changes, in both directions:
NSNotificationCenter* nctr = [NSNotificationCenter defaultCenter];
[nctr addObserver: self selector: @selector(replicationProgress:)
name: kCBLReplicationChangeNotification object: _pull];
[nctr addObserver: self selector: @selector(replicationProgress:)
name: kCBLReplicationChangeNotification object: _push];
}
}
我是否应该在应用程序上设置一个观察者将进入前台并再次运行 updateSyncURL?如果是这样,最好的做法是仅在应用程序进入后台时添加该观察者并在它进入前台后删除?还是从效率/最佳实践的角度来看这无关紧要?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSyncURL) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];