Retrieving Account Info from DBAccountInfo in Dropbox Datastore iOS API

StackOverflow https://stackoverflow.com/questions/23646894

  •  22-07-2023
  •  | 
  •  

Вопрос

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