Dropbox iOS SDK always returns 'YES' for isLinked:

為{幸葍}努か 提交于 2019-12-05 18:46:55

问题


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:


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];
    }
}


来源:https://stackoverflow.com/questions/13033327/dropbox-ios-sdk-always-returns-yes-for-islinked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!