Dropbox数据存储列表iOS上的数据存储 [英] Dropbox Datastore listDatastores on iOS

查看:48
本文介绍了Dropbox数据存储列表iOS上的数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一种方法,该方法将告诉我是否有可用于我的应用程序的数据存储。这样一来,我知道如何处理某些本地数据,因此可以将其添加到数据存储中或跳过它。

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
}

我知道我有一个我的应用程序的数据存储区,但是总是产生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?

推荐答案

我怀疑这里的问题是SDK尚未完成下载调用 listDatastores 之前,有关可用数据存储的信息。

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

您将要等待此信息可用在获得此列表之前。您可以通过在DBDatastoreManager上注册观察者来通知更改:

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:

从smarx编辑

在评论中根据Greg的建议添加代码。

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

这篇关于Dropbox数据存储列表iOS上的数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆