开发者

Save Web Archive with Cocoa

I would like to save a webpage programmatically with Cocoa to the hard disk as a webarchive like Safari.

I've searched for any example programs from Apple yesterday, but I've only found a class reference at Apple Developers page f开发者_运维知识库or a webarchive class. I play a little bit with the webarchive class and unfortunately my solution don't give any ouput.

NSURL *url = [NSURL URLWithString:@"http://www.google.de"];
NSURLRequest *urlRequest = (NSMutableURLRequest*)[NSURLRequest requestWithURL:url
                                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy 
                                                              timeoutInterval:30.0];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                returningResponse:&response
                                            error:&error];
WebArchive *wa = [[WebArchive alloc] initWithData:urlData];
NSData *waData = [wa data];
NSLog(@"%@", [[NSString alloc] initWithData:waData encoding:NSUTF8StringEncoding]);

I hope somebody could post a solution for my problem.

Thanks in advance

Michael


You'll need to instantiate a WebView and load it, but this it's pretty easy:

[[[webView mainFrame] dataSource] webArchive]


I've instantiate a WebView but I don't want that the WebView loads the webarchive at this time. I would like to download a website as a webarchive and save it for later on the hard disk. Later than I load this webarchive and then I will show it in a WebView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜