Ios 未调用上载的文件
我有一个应用程序,我上传一个简单的.csv文件到Dropbox。当我发送这些文件时,它们可以完美地上传,但是没有调用restclientuploadedfile方法。我想用它来向用户显示文件已成功上传。我似乎记得在我运行代码的前几次调用它时,它就停止了,我不明白为什么 以下是一些片段:Ios 未调用上载的文件,ios,objective-c,dropbox,Ios,Objective C,Dropbox,我有一个应用程序,我上传一个简单的.csv文件到Dropbox。当我发送这些文件时,它们可以完美地上传,但是没有调用restclientuploadedfile方法。我想用它来向用户显示文件已成功上传。我似乎记得在我运行代码的前几次调用它时,它就停止了,我不明白为什么 以下是一些片段: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex =
- (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方法。试试这种方法
@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);
}
@接口结果类设备:UIViewController
{
DBRestClient*restClient;
}
#pragma标记-下拉框
-(无效)按链接{
//[[DBSession sharedSession]取消链接];
如果(![[DBSession sharedSession]已链接]){
[[DBSession sharedSession]linkFromController:self];
//在创建任何DBRestClient对象之前,必须链接会话。
//nstr
UIAlertView*al=[[UIAlertView alloc]initWithTitle:@”“消息:@“您必须登录”委托:nil CancelButtontile:@“确定”其他Buttontiles:nil,nil];
[艾尔秀];
[铝释放];
}
}
-(DBRestClient*)restClient{
如果(!restClient){
restClient=
[[DBRestClient alloc]initWithSession:[DBSession sharedSession]];
restClient.delegate=self;
}
返回客户;
}
-(void)restClient:(DBRestClient*)客户端上载文件:(NSString*)destPath
from:(NSString*)srcPath元数据:(DBMetadata*)元数据{
//NSLog(@“文件已成功上载到路径:%@”,metadata.path);
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“成功”消息:@“您的文件已成功上载到Dropbox”委托:自取消按钮:@“确定”其他按钮:无]保留];
[警报显示];
[警报发布];
}
-(void)restClient:(DBRestClient*)客户端上载文件失败witherror:(NSError*)错误{
NSLog(@“文件上载失败,错误-%@”,错误);
}
如果您有任何问题,请告诉我,因为我已经实现了它。主要问题是您更改了上载方法参数: 您正在使用:
- (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不会调用它
我希望这会有帮助当代码“[[self-restClient]uploadFile:fileTitle-toPath:destDir-withParentRev:nil-fromPath:filePath];”执行时,是否检查了“[self-restClient]”的值。是nil吗?好的,我所要做的就是将:字符串更改为srcPath。我的印象是这些名字是可以自由转让的。显然不是!非常感谢。我有:-(void)restClient:(DBRestClient*)客户端上载文件:(NSString*)文件路径from:(NSString*)fromPath元数据:(DBMetadata*)元数据{},但它不起作用。是你的。哦,是的!我只是粘贴了我的最新代码,并试图给出最好的答案。我认为问题在于名称,而不是参数的数量。也许两者都有!