9

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.

1 Answer 1

15

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]; } } 
Sign up to request clarification or add additional context in comments.

4 Comments

While my problem was a more special case (dropbox keeps link in simulator if mac is linked) your solution also applies to any other possible linking problems. This can prevent a lot of headache. Thanks, I will integrate this in my App.
@codingFriend1 You should also make this an answer. Thanks, I was going nuts over this.
what is HAS_RUN_KEY over here??
@Bhushan the HAS_RUN_KEY in the code snippet above is just a reference to some NSString that is used as a key for an NSUserDefaults boolean that we use to track whether the user has run the app before or not. It is only used to illustrate a super-basic way to unlink on first run.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.