Reputation: 14108
I am using the following code in a few different view controllers to listen for Dropbox datastore changes.
Each view controller has a property defined like this:
@property (nonatomic, retain) DBDatastore *store;
And then I add an observer inside listenForRemoteDataChanges
with this code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Listen for remote Dropbox changes
DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];
if(account){
self.store = [DBDatastore openDefaultStoreForAccount:account error:nil];
__weak typeof(self) weakSelf = self;
[[PPDropboxSync sharedDropboxSync] listenForRemoteDataChanges:self.store weakController:weakSelf];
}
}
...and then remove the observer with these methods:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//Stop listening for Dropbox changes
if(self.store) {
[self.store removeObserver:self];
[self.store close];
self.store = nil;
}
}
-(void)dealloc {
//Deallocate NSNotifications (prevents mistakenly calling unavailable notification which causes crashes)
[[NSNotificationCenter defaultCenter] removeObserver:self];
//Stop listening for Dropbox changes
if(self.store) {
[self.store removeObserver:self];
[self.store close];
self.store = nil;
}
}
I keep getting this error and the datastore sync subsequently fails:
ERR: DROPBOX_ERROR_ALREADYOPEN: database_manager.cpp:155: datastore default already open
It appears the DBDatastore
stays open from controller to controller even though they each have their own self.store
property. Why? I thought I was closing the datastore with the viewWillDisappear
method using [self.store close];
Any idea what I'm doing wrong?
Upvotes: 0
Views: 258
Reputation: 16890
As Clifton tried to explain, this means that you are opening it a second time (for the second view controller) before you close the first one. A datastore may only be opened once, until it is closed, so that is what the error is trying to tell you.
Perhaps you can use a singleton pattern?
Upvotes: 2