2011-03-21 18 views
4

我想知道如何檢查和使用ASIHTTPiPhone覈對和更新文件

更新文件爲我的iPhone到目前爲止,我有:

我要檢查舊版本中的緩存目錄並將最後修改的標題與緩存目錄中文件的修改日期進行比較,然後進行替換。

回答

8

嘗試這樣的事:

if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){ 
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error]; 
    NSDate *fileDate =[dictionary objectForKey:NSFileModificationDate]; 
    NSDate *today =[NSDate date]; 
    if (![[[today dateByAddingTimeInterval:-(60*60*24)] earlierDate:fileDate] isEqualToDate:fileDate]) { 
     //file is less than 24 hours old, use this file. 
    } 
    else{ 
     //file is older than 24 hours, replace it 
    } 
} 
0

由於您使用下載高速緩存,它會爲你做到這一點。當請求完成時,響應應該是最新的版本,並且如果請求已經被更新,請求將僅再次下載實際內容。

我該如何將它保存在iPhone上?

最簡單的方法就是設置一個downloadDestinationPath的請求,它會保存在您的文件。