Dropbox Datastore listDatastores on iOS

2019-07-26 16:22发布

I'm trying to write a method that will tell me if there are any datastores already available for my app. This is so I know what to do with some local data so I can add it to the datastore or skip it.

-(BOOL)isDatastorePresent
{
  DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];
  DBDatastoreManager *dsm = [DBDatastoreManager managerForAccount:account];
  DBError *__autoreleasing *error = NULL;
  NSLog(@"Datastores: %@",[dsm listDatastores:error]); //-- Log: empty array
  NSLog(@"Error: %@",error); //-- Log: (null)

  NSLog(@"# datastores: %lu",(unsigned long)[[dsm listDatastores:nil] count]); 
  //-- Log: 0
}

I know I have a datastore for my app already, but this always yields 0 datastores. Any ideas on what I might be doing wrong?

标签: dropbox-api
2条回答
姐就是有狂的资本
2楼-- · 2019-07-26 16:49

I suspect the issue here is that the SDK hasn't finished downloading the information about the available datastores before you call listDatastores.

You'll want to wait for this information to be available before getting this list. You can do this by registering an observer on the DBDatastoreManager to be notified of changes:

https://www.dropbox.com/developers/datastore/docs/ios#DBDatastoreManager.addObserver:block:

EDIT from smarx:

Adding code per Greg's suggestion in the comments.

DBObserver dsmBlock = ^() {
  NSLog(@"Datastores: %@",[dsm listDatastores:error]);
  NSLog(@"Error: %@",error);
  NSLog(@"#datastores: %lu",(unsigned long)[[dsm listDatastores:nil] count]);    
}
[dsm addObserver:self block:dsmBlock];
[dsmBlock invoke];
查看更多
够拽才男人
3楼-- · 2019-07-26 16:53

This may sound strange, but adding the observer turned out to not be necessary. I just pulled the datastore list as shown in my question.

The issue seemed to be that the Datastore API got "stuck" somehow. I started doing some other sync operations to see if the Datastore browser was responding, and nothing was happening. After logging out of my Dropbox account (on the web) and back in again, the syncs started occurring and the datastore list started populating out of the blue.

查看更多
登录 后发表回答