Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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);
}];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top