3
對於客觀的C還是新的我已經發現了令人驚歎的AFNetworking網絡類。AFNetWorking下載會話不會更新我的文件
使用DIC我有我的代碼下載我的文件,並寫入到NSDocumentDirectory
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"http://myAdress/Menu.plist"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{
NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
return [documentsDirectoryPath URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
NSDictionary *dicMenuPlist = [NSDictionary dictionaryWithContentsOfFile:[filePath path]];
NSLog(@"Dic Menu Plist = %@",dicMenuPlist);
}];
[downloadTask resume];
這工作得很好,但是當我在Menu.plist改變一些文件中的更改不會出現,我不得不刪除我的應用程序,然後下載已更改的文件。
我不明白爲什麼我必須這樣做。
有人可以幫我嗎?
只是刪除之前下載 – sage444
沒有本地文件,但我想不刪除應用程序要上傳的文件,用戶必須刪除該應用獲取最後的數據? ? – user3237416
不,意思是刪除'Menu.plist'的本地副本不是應用程序本身 – sage444