문제

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