我有一个保存在临时目录中的HTML文件,像这样:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentDirectory = NSTemporaryDirectory();
NSString *documentPath = [documentDirectory stringByAppendingPathComponent:@"mydocument.html"];
[fileManager createFileAtPath:documentPath contents:myHTMLDocumentData attributes:nil];
文档已创建在我的临时文件中。之后,我想在Safari中打开此文档,但无法正常工作:
NSURL *url = [NSURL fileURLWithPath:documentPath];
[[UIApplication sharedApplication] openURL:url];
屏幕上没有任何反应,也没有出现错误... 然而,如果我将"url"替换为@"http://google.fr",Safari会启动并显示google.fr,我可以通过在Safari中输入"url file://localhost..../myHtmlDocument.html"来访问我的临时文件。 希望我能帮到你。