내 코드가 웹 서버의 XML 파일에서 url의 내용을 쓰고 문자열에 내용을 저장 한 다음 문서 디렉토리의 로컬 파일에 저장합니다. 내가이 뷰를 다시 실행할 때에도 항상 장치에 캐시 된 내용을 가져오고 웹 서버에서 업데이트를 가져 오지 않고 처음으로로드하면 모든 것이 잘 진행됩니다.stringWithContentsOfURL 캐시를 사용하여 URL 내용을 문자열로 작성하십시오.
매번 서버의 파일에서 내용을 읽도록 강제하는 방법은 무엇입니까?
NSString * path = @"http://my-domain-name.com/myGlobalFile.xml";
NSString * myStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:path] encoding:NSUTF8StringEncoding error:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
localFilePath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFile.xml"];
[myStr writeToFile:localFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
프로그램에서 위의 스 니펫을 수행하는 위치는 어디입니까? writeToFile이 리턴 할 수있는 오류 오브젝트를 점검 할 수도 있습니다. – onnoweb