我有一个应用程序,我将一个简单的.csv文件上传到Dropbox。我发送文件时文件上传完美,但不调用restClient uploadedFile方法。我希望这用它来向用户显示文件已成功上传。我似乎记得它是我运行代码的前几次调用,但后来它停止了,我不明白为什么。
以下是一些片段:
- (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方法。
答案 0 :(得分: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);
}
如果您有任何问题,请告诉我,因为我已经实施了。
答案 1 :(得分: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不会调用它。
我希望这会有所帮助