2012-09-11 17 views
0

目前我正在簡單的Drop Box應用程序在iPhone中,使用Dropbox_SDK來開發這個應用程序,我必須將文件存儲在下拉框路徑文件夾中,其作品不錯,然後我試圖從Dropbox中檢索(下載)該文件並存儲在iPhone設備中,但設備路徑,我不知道,如何設置設備路徑?請幫我如何在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); 
} 

回答

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]; 
+0

感謝您的答覆,現在我檢查,並更新你 – SampathKumar

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]; 
     } 
    } 
相關問題