我正在使用 iOS Dropbox SDK,想检查我的应用程序是否已与 Dropbox 帐户相关联。所以我这样做:
if (self.isLinked) {
NSLog(@"linked");
}
但是 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];
}
}
关于objective-c - Dropbox iOS SDK 始终为 isLinked : 返回 'YES',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13033327/