我正在使用 iOS Dropbox SDK,想要检查我的应用程序是否已与 Dropbox 帐户链接。所以我这样做:
if (self.isLinked) {
NSLog(@"linked");
}
However self.isLinked
总是返回YES
。即使在清理并重置 iPhone 模拟器后也是如此。
仅当在 iOS 模拟器中运行时才会发生这种情况,而不是在真实设备上运行时。我不知道为什么会发生这种情况,但如果模拟器的主机 Mac 与 Dropbox 帐户链接,模拟器上的 Dropbox SDK 也会链接。
要在模拟器中获得真实的行为,请在 Dropbox 偏好设置中取消与 Mac 的链接。
在 2012 年中期的某个时候(找不到 iOS SDK 版本日志),Dropbox iOS SDK 行为发生了更改,通过卸载/重新安装应用程序(甚至在设备上)来保留“链接”状态。因此,在接收“链接”回调时执行某些操作的应用程序(例如我的)在重新安装后将无法工作。
一种解决方案是在首次运行时取消链接。像这样:
- (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];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)