5

We use Dropbox Datastore API in our application and it works correctly. We've decided to add a iOS8 widget to our app. But we can't access to app datastore from it. We followed Datastore API install guide, except that you can't add URL Schema to a widget. What is problem?

UPDATE 1

When the below code (in the widget) runs, it returns nil:

DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];

So I think Dropbox SDK can't retrieval authentication data, which it has saved when authentication is done at host app. Where does dropbox save these information? In keychain? Can I get access token from the host app and use it directly in widget? Because widgets can show a UIViewController for doing authentication.

UPDATE 2

I read Dropbox Core API source code. It seems dropbox saves authentication information in keychain. So I set a keychain group for host app and widget. I tested and both of them can read and write on same keychain. But still [[DBAccountManager sharedManager] linkedAccount] on the widget returns null and on the host app return linked account!

2

1 Answer 1

3

setting a keychain group was the first step to be able to use Dropbox account from your extension, but you also have to make a modification in DBKeychain-iOS.m !

By default it's setting kSecAttrService to something build with application's bundle identifier !

In your main app it will be "com.coybit.myapp" but in you extension it will be "com.coybit.myapp.extensionName" !

You can hardcode the kSecAttrService value to com.coybit.myapp.dropbox.auth or use a method that will only keep the first 3 elements of the bundle identifier to build 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:@"."];
}

The initialize function will then looks like :

+ (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];
}
4
  • This will enable complete access from extensions itself? Like making a DBRecord change would reflect instantly on other clients? I also wonder of the hosp app is treated as another client if I made datastore changes from the extension. I wish we had some official guidance.
    – jasonIM
    Commented Nov 24, 2014 at 8:12
  • 1
    I'm not using DBRecord but you can have a look at my app if you want to make some tests ! It's available for free on the AppStore : itunes.apple.com/us/app/nastify/id917241569?mt=8 and the source code of the application is available here : github.com/sylverb/NAStify . Basically the main app and the app extension will share the same local data after that !
    – Sylverb
    Commented Nov 25, 2014 at 8:55
  • thanks for your reply. I'd have to find a way to get the source files from dropboxSDK.framework and probably change those values. Thanks for your guidance. I wish there was more help from Dropbox on Extensions on iOS8. @smarx.
    – jasonIM
    Commented Dec 3, 2014 at 17:50
  • My project NAStify is including DropboxSDK source code with modifications needed for use Dropbox shared account from app extension ! Just change your app group in my code as I've hardcoded it in the code (if I remember well).
    – Sylverb
    Commented Dec 8, 2014 at 8:50

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.