I'm trying to get a user's display name from the Dropbox Datastore API. The documentation for iOS says that DBAccountInfo is retrieved in the background, and to use an observer.

This is what I'm trying, but I'm getting nothing back (the block never fires):

NSLog(@"Here");
//-- Log: Here --

[[DBAccountManager sharedManager] addObserver:self block:^(DBAccount *acctInfo) {
  DBAccountInfo *info = acctInfo.info;      
  NSLog(@"Info: %@",info);
  //-- Log: <nothing> --
}];

Any idea what I am doing wrong?

有帮助吗?

解决方案

It looks like you're adding an observer to the DBAccountManager, which will only fire when an account is linked or unlinked.

If you want to observe when the account info changes, you should add an observer to the DBAccount. Take a look at the DBAccount.addObserver:block: documentation.

其他提示

Here is the full code for anyone else that might be having trouble with this:

//Use weak reference because we are using `account` in a block
__weak DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];

[account addObserver:self block:^(){
  DBAccountInfo *info = account.info;
  NSLog(@"Info: %@",info);
}];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top