简体   繁体   中英

Linking to Dropbox

I have a curious problem. My app should link to Dropbox and should be able to up/download files. I have a Button calles "Connect to Dropbox". When this button is pressed the app should link to Dropbox.

- (IBAction)btnLoginClick:(id)sender {
    [[DBSession sharedSession] linkFromController:self];
}

When this action is called everything works. The Dropbox.app is loaded and asks for permissions and so on.

If I change the function to look like this:

- (IBAction)btnLoginClick:(id)sender {
    [[appDelegate getDropboxService] link:self];
}

Then the Dropbox.app is opened and it is asked for permission but then the app isn't linked to Dropbox.

I get the following Error:

[WARNING] DropboxSDK: error making request to /1/metadata/dropbox - Token is invalid. 

the function in the appDelegate only Returns the Dropbox Object or if it is nil it will be created. The Link function just calls the same line like in the first code block.

[[DBSession sharedSession] linkFromController:self];

I don't know why this happens or what I'm doing wrong.

Greetings Alex

I had same issue. In my case I had created an instance of restClient before app linked to Dropbox. May be this helps

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            NSLog(@"App linked successfully!");
            //now you can call restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        }
    }
}

My problem was that when a DropBox user has the official DropBox app installed, your app punts the authentication over to that app, instead of using a built-in sheet. If your app is set to quit when it is no longer key, then the shared session ([DBSession sharedSession]) is no longer there when your app receives focus again (ie relaunches). This led (in my case) to an infinite loop of relinking, failing, trying to relink again, etc.

The fix for me was to recreate the shared session in the - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM