Dropbox Datastore listDatastores on iOS

早过忘川 提交于 2019-12-11 11:14:43

问题


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?


回答1:


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];



回答2:


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.



来源:https://stackoverflow.com/questions/23664650/dropbox-datastore-listdatastores-on-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!