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];
};

私が言ったように、それはファイルを完全にアップロードしますが、uploadedFile メソッドへの呼び出しを取得しません。

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 に答える