Open a .webarchive on the iphone?

拜拜、爱过 提交于 2019-11-30 09:38:02

webarchive is supported on iOS. Just load it on UIWebView. It just works!

for loading a webarchive on your bundle, just do

NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"myFile"
     withExtension:@"webarchive"];

[webView loadRequest:[NSURLRequest requestWithURL:fileURL]];

webview is your UIWebview

a .webarchive is just a plist; theoretically, you could read it using NSPropertyListSerialization and then build a local file structure on the phone, then pump that into a UIWebView. Or use AirSharing.

Expanding a little on suggestions above, if you just want to grab the HTML, the following code snippet may be a good starting point. By inspecting the webMainResource dictionary you can extract other material too, such as images.

#define WEB_ARCHIVE @"Apple Web Archive pasteboard type"

- (NSString*) htmlStringFromPasteboard;
{
    NSData* archiveData = [[UIPasteboard generalPasteboard] valueForPasteboardType:WEB_ARCHIVE];

    if (archiveData)
    {
        NSError* error = nil;
        id webArchive = [NSPropertyListSerialization propertyListWithData:archiveData options:NSPropertyListImmutable format:NULL error:&error];

        if (error)
        {
            return [NSString stringWithFormat:@"Error: '%@'", [error localizedDescription]];
        }
        NSDictionary* webMainResource = [webArchive objectForKey:@"WebMainResource"];
        NSData * webResourceData = [webMainResource objectForKey:@"WebResourceData"];

        NSString* string = [[NSString alloc] initWithData:webResourceData encoding:NSUTF8StringEncoding];

        return [string autorelease];
    }

    return @"No WebArchive data on the pasteboard just now";

}

AirSharing on the iPhone will open webarchive files, but I've no idea if they are doing it all themselves or using native webarchive support.

See http://www.avatron.com/products/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!