Question

I'm integrating the Dropbox Sync SDK into my iOS app. I want to set it up so that when the user is in a UIDocument, and then the app becomes inactive (home button, lock, etc.), and then the file is changed by someone else in Dropbox, and then the user returns to the app, they will be notified that changes were made elsewhere. Here's what I have now:

In my viewDidLoad I have:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForNewerStatus) name:UIApplicationDidBecomeActiveNotification object:nil];

Then I have this method:

- (void)checkForNewerStatus
{
    if (self.dropboxFile.newerStatus)
    {
       //alert user of changes
    }
}

This works semi-desirably. When the app first comes back, self.dropboxFile.newerStatus returns NO. If I leave the app and come back a second time, then it returns YES. But I need it to return YES the first time the app comes back. This isn't time related - I can wait several minutes before coming back, and it still fails the first time and succeeds the second. Any ideas?

Many thanks!

Note: this problem only occurs if the app becomes inactive and then the file is changed. If the file is changed while the app is still active, and then the app leaves and comes back, it alerts as expected.

Était-ce utile?

La solution

@rmaddy's comment above is correct. Just moving it into an answer.

You need to add an observer on your DBFile to get notified when it changes. What's happening is that your app is being restarted and your immediately checking the status, but since the app just started, it hasn't had time yet to talk to the server and learn about the newer file content. An observer on the DBFile will fire as soon as the app is able to communicate with the server and find out about the change.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top