0

目前我在 iPhone 中使用简单的 Dropbox 应用程序,使用 Dropbox_SDK 开发这个应用程序,我必须在 drop box 路径文件夹中存储一个文件并且它的工作正常,然后我尝试从 Dropbox 中检索(下载)该文件并存储在里面iPhone设备,但是设备路径,我不知道,如何设置设备路径?请帮我

提前致谢

我试过这个供你参考:

- (void)viewDidLoad
{
    NSString *DropBoxpath = @"/Public/sam.txt";
    NSString *devicepath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
    [[self restClient] loadFile:DropBoxpath destDir:devicepath];
}
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)localPath
{
    NSLog(@"File loaded into path: %@", localPath);
}

- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error {
    NSLog(@"There was an error loading the file - %@", error);
}
4

3 回答 3

0

You Have to use NSFileManager and document directory for saving files. NSFieManager operation is needed for same. You can also use third party API for downloading

https://github.com/H2CO3/HCDownload/

于 2012-09-11T14:13:29.007 回答
0

这是用于下载文件表单保管箱:

 -(void) DBdownload:(id)sender
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Example.txt"];
        NSError *error;

        [self.restClient loadFile:@"/example/Example.txt" intoPath:filePath];

        if (filePath) { // check if file exists - if so load it:
            NSString *tempTextOut = [NSString stringWithContentsOfFile:filePath
                                                              encoding:NSUTF8StringEncoding
                                                                 error:&error];
        }
    }
于 2012-09-11T14:17:33.847 回答
0
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         NSString *filePath = [NSString stringWithFormat:@"%@/", [paths objectAtIndex:0]];   

    //    // Download and write to file
         NSURL *url = [NSURL URLWithString:@"dropbox url.com"];
         NSData *urlData = [NSData dataWithContentsOfURL:url];

         [urlData writeToFile:filePath atomically:YES];
于 2012-09-11T13:52:35.013 回答