2014-03-26 4 views
0

다운로드 폴더에 대한 정적 파일 경로가 있습니다. 파일은 잘 다운로드되지만 새로운 파일을 다운로드하면 이전 파일이 새 것으로 바뀝니다. 정적 경로 때문에 나는 생각합니다. 새로운 코드를 다운로드 할 때마다 타임 스탬프를 어떻게 추가합니까? 예전의 파일을 실제 배열에서 "원본"파일로 다운로드 할 수 있습니까? 여기 내 filePath에 타임 스탬프를 추가하는 방법은 무엇입니까?

내 다운로드 코드입니다 : 당신에게 줄 것이다

-(void) Savefile { 

    [self.downloadfile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
     if (error) { 

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wooopss!" message:@"Download failed. Try Again..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
     else if (data) { 


      [data writeToFile:@"/Users/Danny/Desktop/PDFFile/hello.pdf" atomically:NO ]; 



      NSLog(@"Downloading file..."); 

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Downloading" message:@"File is being downloaded..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
    }]; 

} 

답변

1
NSDateFormatter *dateFormatter = [NSDateFormatter new]; 
[dateFormatter setDateFormat:@"MMddYYYYmmss"]; 

NSString *filePath = [NSString stringWithFormat:@"/Users/Danny/Desktop/PDFFile/hello_%@.pdf", [dateFormatter stringFromDate:[NSDate date]]]; 

이 :

/Users/Danny/Desktop/PDFFile/hello_032620144401.pdf 

회원님이 무슨 뜻인지 전혀 확인 : 심지어 어쩌면

또는 다운로드 파일에의 "원본"파일 이름을 지정하십시오.실제 배열

+0

감사합니다. 오, 그 의미는 오리지날 파일 이름입니다. 파스의 데이터베이스 내 파일에 주어진 이름과 같습니다. 거기에서이 파일들을 저장하고 있습니다. – DannyK

+0

이 "날짜의 선택자 문자열에 대해 알려진 클래스가 없습니다"라는 메시지가 나타납니다. – DannyK

+0

[NSDate *] date]]]]]; 하지만 작동하지 않습니다 – DannyK

관련 문제