如何在iPhone设备中存储(下载)文件?

时间:2012-09-11 13:39:25

标签: iphone path download device dropbox

目前我正在使用iPhone中的简单Drop Box应用程序,使用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);
}

3 个答案:

答案 0 :(得分: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];

答案 1 :(得分:0)

您必须使用NSFileManager和文档目录来保存文件。同样需要NSFieManager操作。您也可以使用第三方API进行下载

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

答案 2 :(得分:0)

这是从dropbox下载文件: