Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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);
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top