有人知道是否可以通过编程方式在iPhone上打开.webarchive吗?.webarchive是Safari将网页及其相关资源打包成单个文件的方式。
我试着在移动safari中创建一个,并浏览到一个链接,但它不起作用……
注意:我有点希望这可以在没有第三方应用程序的情况下完成,因为这将是一个很好的方式来打包一个WebApp在iphone上使用,而不需要第三方工具。
发布于 2011-02-10 09:05:48
iOS支持webarchive。把它加载到UIWebView上就行了。它真的很有效!
要在捆绑包中加载webarchive,只需执行以下操作
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"myFile"
withExtension:@"webarchive"];
[webView loadRequest:[NSURLRequest requestWithURL:fileURL]];webview就是你的UIWebview
发布于 2008-10-22 13:37:04
.webarchive只是一个plist;理论上,您可以使用NSPropertyListSerialization读取它,然后在手机上构建一个本地文件结构,然后将其放入UIWebView中。或者使用AirSharing。
发布于 2011-07-06 06:50:11
如果您只是想获取HTML,那么下面的代码片段可能是一个很好的起点。通过查看webMainResource字典,您还可以提取其他材料,例如图像。
#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";
}https://stackoverflow.com/questions/225699
复制相似问题