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?
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.
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.