0

我有一个应用程序,我将一个简单的 .csv 文件上传到 Dropbox。当我发送文件时,文件上传完美,但未调用 restClient UploadFile 方法。我想用它来向用户显示文件已成功上传。我似乎记得在我运行代码的前几次调用它,但后来它停止了,我不明白为什么。

以下是一些片段:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)       //Cancel
{
}
else if (buttonIndex == 1)      //Send
{
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *CCD = [docPath stringByAppendingPathComponent:@"CCD.csv"];


    if ([[NSFileManager defaultManager] fileExistsAtPath:CCD])
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSString *machineName = [defaults objectForKey:@"machineName"];
        NSString *fileTitle = [defaults stringForKey:@"setTitle"];
        NSMutableString *filePath = [NSMutableString string];
        [filePath appendString:docPath];
        [filePath appendString:@"/CCD.csv"];
        NSString *destDir = @"/";
        [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"Sending to %@...", machineName]];
        [[self restClient] uploadFile:fileTitle toPath:destDir
                        withParentRev:nil fromPath:filePath];

    }

} 
}
- (void)restClient:(DBRestClient*)restClient uploadedFile:(NSString*)filePath {
    NSLog(@"File uploaded successfully");
    [SVProgressHUD dismiss];
};

正如我所说,它完美地上传了文件,我只是没有调用 uploadFile 方法。

4

2 回答 2

0

试试这个方法。。

@interface ResultClass_vice : UIViewController<DBRestClientDelegate>
{
DBRestClient *restClient;
}

#pragma mark - DropBox

- (void)didPressLink {
   // [[DBSession sharedSession]unlinkAll];

    if (![[DBSession sharedSession] isLinked]) {
        [[DBSession sharedSession] linkFromController:self];
        // Session must be linked before creating any DBRestClient objects.

        //   nstr
        UIAlertView *al=[[UIAlertView alloc]initWithTitle:@"" message:@"You must have to Login"  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [al show];
        [al release];

    }
}

- (DBRestClient *)restClient {
    if (!restClient) {
        restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        restClient.delegate = self;
    }
    return restClient;
}


- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
              from:(NSString*)srcPath metadata:(DBMetadata*)metadata {

    //NSLog(@"File uploaded successfully to path: %@", metadata.path);
    UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"Success" message:@"Your file is successfully uploaded to Dropbox" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]retain];
    [alert show];
    [alert release];

}

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
    NSLog(@"File upload failed with error - %@", error);
}

如果您有任何问题,请告诉我,因为我已经实现了它。

于 2013-10-15T09:47:19.257 回答
0

主要问题是您更改了上传方法参数:

您正在使用:

- (void)restClient:(DBRestClient*)restClient uploadedFile:(NSString*)filePath {
     NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

你应该使用:

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
from:(NSString*)srcPath metadata:(DBMetadata*)metadata {
    NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

如果您更改参数数量,您将创建一个新函数,因此 Dropbox SDK 不会调用它。

我希望这会有所帮助

于 2013-10-15T10:25:16.823 回答