从iOS8小部件访问Dropbox数据存储区

Coy*_*Bit 5 widget objective-c dropbox ios ios8

我们在应用程序中使用Dropbox Datastore API,它可以正常工作.我们决定在我们的应用中添加iOS8小部件.但是我们无法从中访问app数据存储区.我们遵循数据存储API安装指南,但您无法将URL架构添加到窗口小部件.有什么问题?

更新1

当下面的代码(在小部件中)运行时,它返回nil:

DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];
Run Code Online (Sandbox Code Playgroud)

所以我认为Dropbox SDK无法检索身份验证在主机应用程序中完成时保存的身份验证数据.dropbox在哪里保存这些信息?在钥匙串?我可以从主机应用程序获取访问令牌并直接在小部件中使用它吗?因为小部件可以显示UIViewController以进行身份​​验证.

更新2

我读了Dropbox Core API源代码.似乎dropbox将身份验证信息保存在钥匙串中.所以我为主机app和widget设置了一个keychain组.我测试过,他们都可以在同一个钥匙串上读写.但是小部件上的[[DBAccountManager sharedManager] linkedAccount]仍返回null并且在主机应用程序上返回链接帐户!

Syl*_*erb 3

设置钥匙串组是能够从扩展程序中使用 Dropbox 帐户的第一步,但您还必须在 DBKeychain-iOS.m 中进行修改!

默认情况下,它将 kSecAttrService 设置为使用应用程序的包标识符构建的内容!

在您的主应用程序中,它将是“com.coybit.myapp”,但在您的扩展中,它将是“com.coybit.myapp.extensionName”!

您可以将 kSecAttrService 值硬编码为 com.coybit.myapp.dropbox.auth 或使用仅保留包标识符的前 3 个元素的方法来构建 kSecAttrService :

+ (NSString *)mainBundleName
{
    // Always return main application bundle name (for app extensions, remove last component)
    NSMutableArray *components = [NSMutableArray arrayWithArray:[[[NSBundle mainBundle] bundleIdentifier] componentsSeparatedByString:@"."]];
    while ([components count] > 3) {
        [components removeLastObject];
    }
    return [components componentsJoinedByString:@"."];
}
Run Code Online (Sandbox Code Playgroud)

初始化函数将如下所示:

+ (void)initialize {
    if ([self class] != [DBKeychain class]) return;
    NSString *keychainId = [NSString stringWithFormat:@"%@.dropbox.auth", [self mainBundleName]];
    kDBKeychainDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                       (id)kSecClassGenericPassword, (id)kSecClass,
                       keychainId, (id)kSecAttrService,
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
                       @"keychain_access_group_name",(id)kSecAttrAccessGroup,
#endif
                       nil];
}
Run Code Online (Sandbox Code Playgroud)