gpt4 book ai didi

Objective-c/iOS - 使用 Safari 打开本地 html 文件

转载 作者:可可西里 更新时间:2023-11-01 06:22:23 28 4
gpt4 key购买 nike

我有一个 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 启动,我可以通过键入 url“file://localhost..../”来访问我的临时文件Safari 中的 myHtmlDocument.html”。

希望你能帮助我

最佳答案

您无法通过 Safari 打开应用程序包中驻留的文档(请参阅 iOS Security Model)。

您需要使用 UIWebView 在您的应用程序中使用 – loadHTMLString:baseURL: 显示您的文档内容;例如:

UIWebView* webView = [[[UIWebView alloc] initWithFrame:rect] autorelease];
[webView loadHTMLString:myHTMLSource baseURL:nil];
[self.view addSubview:webView];

关于Objective-c/iOS - 使用 Safari 打开本地 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11035564/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com