(아직까지는 확인되지 않은) 감사합니다. WebKit API (documentation)의 메소드를 사용하면 DOM을 쉽게 수정할 수 있습니다. 까다로운 점은 DOM을 수정하고 WebArchive에 수정 사항을 다시 쓰려는 것입니다. 새 WebArchive를 저장하는 것만으로는 수정 내용이 보존되지 않으므로 작동하지 않습니다. 따라서 새 소스를 작성해야합니다. 여기에 그렇게 할 몇 가지 코드 (여기에 웹보기가 webview
하고 원래 WevArchive가 archivepath 매에 위치하고 있으며 수정 된 버전뿐만 아니라이 기록 될 것입니다)입니다 :
//Get the string representation of the current DOM tree
NSString *sourceString = [(DOMHTMLElement *)[[[webview mainFrame] DOMDocument] documentElement] outerHTML];
NSData *sourceData = [sourceString dataUsingEncoding:NSUTF8StringEncoding];
//Load the archive from disk to a dictionary (it's a plist)
NSMutableDictionary *archive = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL fileURLWithPath:archivePath]];
//Modify the main HTML
[(NSMutableDictionary *)[archive objectForKey:@"WebMainResource"] setObject:sourceData forKey:@"WebResourceData"];
//Write the plist back out
NSData *data = [NSPropertyListSerialization dataFromPropertyList:archive format:NSPropertyListBinaryFormat_v1_0 errorDescription:nil];
[data writeToURL:[NSURL fileURLWithPath:ArchivePath] atomically:YES];
이이 때문에 해킹의 약간이다 문서화되지 않은 아카이브 형식의 내부 구조에 의존하지만, 나는 그것이 크게 변하지 않을 것이라고 꽤 안전하게 추측 할 수 있다고 생각합니다.
좋습니다. 감사. – Jaycee