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];
    }
}
4
  • 1
    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. Commented Oct 30, 2012 at 13:10
  • @codingFriend1 You should also make this an answer. Thanks, I was going nuts over this.
    – fzwo
    Commented Apr 15, 2013 at 11:00
  • what is HAS_RUN_KEY over here??
    – Bhushan
    Commented Nov 25, 2013 at 9:27
  • 2
    @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. Commented Nov 26, 2013 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.