Dropbox iOS SDK always returns 'YES' for isLinked:
dropbox, ios, objective-c
Solution
Sometime in mid-2012 (can't find the iOS SDK version log) the Dropbox iOS SDK behaviour changed to retain 'link' status through uninstall/reinstall of an app (even on device). As a result, apps that perform some action on receiving the 'linked' callback (like mine) would not work after a reinstall.
One solution is to unlink on first-run. Something like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[NSUserDefaults standardUserDefaults] objectForKey:HAS_RUN_KEY] == nil)
{
// ensure you have a DBSession to unlink
if ([DBSession sharedSession] == nil)
{
DBSession* dbSession = [[[DBSession alloc] initWithAppKey:DROPBOX_KEY appSecret:DROPBOX_SECRET root:kDBRootAppFolder] autorelease];
[DBSession setSharedSession:dbSession];
}
// unlink
[[DBSession sharedSession] unlinkAll];
// set 'has run' flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:HAS_RUN_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
Problem
I'm using the iOS Dropbox SDK and want to check if my App is already linked with a Dropbox account. So I do: ``` if (self.isLinked) { NSLog(@"linked"); } ``` However `self.isLinked` always returns `YES`. Even after cleaning and resetting the iPhone Simulator. This only occurs when running in the iOS simulator not on a real device. I don't know why this happens, but the Dropbox SDK on the Simulator also is linked if its host Mac is linked with a Dropbox account. To get realistic behavior in the Simulator unlink your Mac in the Dropbox Preferences.