tokan_one
tokan_one

Reputation: 899

Dropbox iOS Core SDK not downloading files

When I call the DBRestClient to download a file to a given path, the API does not call the loading functions.

For example:

- (void) downloadFiles:(NSMutableArray *)files
{
    NSLog(@"%@", files);
    itemsToBeDownloaded = [[NSMutableArray alloc] initWithArray:files];
    restClient = [self restClient];
    for (NSString *string in files)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/Dropbox%@", string]];
        [restClient loadFile:string intoPath:filePath];
    }
}

Printing files returns ( "/Blank.pdf" )

Printing string returns /Blank.pdf

Printing filePath returns /var/mobile/Applications/0C506400-7142-41E2-9F3D-0965985CED9E/Documents/Dropbox/Blank.pdf

So the function is called and knows the files and their path's to download.

However, when I call [restClient loadFile:string intoPath:filePath];, nothing happens. I have the delegate methods in:

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath
{
    NSLog(@"Called!");
}

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath contentType:(NSString *)contentType
{
     NSLog(@"Called!");
}

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath contentType:(NSString *)contentType metadata:(DBMetadata *)metadata
{
    NSLog(@"%@", destPath);
    NSLog(@"%@", contentType);
    NSLog(@"%@", metadata);
}

- (void) restClient:(DBRestClient *)client loadFileFailedWithError:(NSError *)error
{
    NSLog(@"Error downloading file: %@", error);
}

No Called! statement is produced. It seems the RestClient is not downloading the data.

Another note: restClient = [self restClient]; does return a valid DBRestClient, so I know it is valid. However, the call to load the file is not being called.

Is there a specific reason the call to loadFile: is not being made? I have it loading Metadata just fine.

EDIT: a call to loadMetadata: at string does NOT call the loadMetadata delegate method.

EDIT 2: code below lists how the file's array is claimed:

- (void) downloadFiles
{
    NSMutableArray *filesToDownload = [[NSMutableArray alloc] init];
    for (int i = 0; i < [[itemsToDownload allKeys] count]; ++i)
    {
        for (NSString *string in [itemsToDownload objectForKey:[[itemsToDownload allKeys] objectAtIndex:i]])
        {
            [filesToDownload addObject:[NSString stringWithFormat:@"%@%@", [[itemsToDownload allKeys] objectAtIndex:i], string]];
        }
    }
    [dropboxController downloadFiles:filesToDownload];
}

Upvotes: 1

Views: 2028

Answers (2)

tokan_one
tokan_one

Reputation: 899

So I figured out the entire problem. Turns out, you can't call the rest client methods from the background thread, it's got to be called on a main thread.

Upvotes: 4

SpaceDust__
SpaceDust__

Reputation: 4914

First I thought you are calling wrong path in dropbox, but event then you should have receive error message.

If your restClient returns the delegate method even with wrong path your - (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error should have been called.

I doubt your restClient is initiated correctly.

in your .h file:

#import <DropboxSDK/DropboxSDK.h>
@property (nonatomic, strong) DBRestClient *restClient;

in.your.m file:

#import <DropboxSDK/DropboxSDK.h>
@synthesize restClient = _restClient;
- (DBRestClient *)restClient {
    if (!_restClient) {
        _restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        _restClient.delegate = self;
    }
    return _restClient;
} 

then try to call your

[[self restClient] loadFile:@"string" intoPath: @"pathstring" ];

Upvotes: 0

Related Questions