简体   繁体   中英

Dropbox Datastore API Error on iOS: datastore default already open

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM