Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a .webarchive on the iphone?

Does anyone know if you can programmatically open a .webarchive on the iPhone? A .webarchive is Safari's way of packaging up a webpage and it's associated resources into a single file.

I tried creating one and browsing to a link to one in mobile safari, but it didn't work....

Note: I was kind of hoping this could be done without a 3rd party app, as it'd be a nice way to package up a WebApp for use on the iphone without needing a third party tool.

like image 378
Brad Parks Avatar asked Oct 22 '08 13:10

Brad Parks


People also ask

How do I open a WEBARCHIVE file on my iPhone?

Web archive files work just like a web page–they can be opened in Safari on your iPad, iPhone or macOS devices. Simply open them from the Files app, or the Finder. On macOS Big Sur, you may get an error that the web archive isn't signed from a trusted developer.

How do I open a .WEBARCHIVE file?

How to open a WEBARCHIVE file. You can open a WEBARCHIVE file in Safari (macOS, iOS) to view the webpage it contains. You can also open WEBARCHIVE files in the iCab and Cruz web browsers.

How do I convert a WEBARCHIVE to PDF?

To create a PDF from the currently open web page, choose Convert Web Page To PDF. Then select a location, type a filename, and click Save. To add a PDF of the currently open web page to another PDF, choose Add Web Page To Existing PDF. Then locate and select the existing PDF, and click Save.

Where is the archive tab on Safari?

Save an entire webpage In the Safari app on your Mac, choose File > Save As. Choose Format > Web Archive or Format > Page Source. Web archive: Saves all graphics, and links work as long as the destination webpages are available.


3 Answers

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

like image 130
Duck Avatar answered Sep 19 '22 06:09

Duck


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.

like image 31
Ben Gottlieb Avatar answered Sep 18 '22 06:09

Ben Gottlieb


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";

}
like image 30
Obliquely Avatar answered Sep 20 '22 06:09

Obliquely