简体   繁体   English

iPhone:在Safari中访问文档目录文件路径

[英]iPhone:Accessing documents directory file path in Safari

I have placed a file programmatically in documents folder on iPhone like below. 我已经以编程方式将文件放置在iPhone的“文档”文件夹中,如下所示。

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSError *error;
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"myfilename.xxxxx"];


NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfilename.xxxxx"];
BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
    NSAssert1(0, @”Failed to create writable database file with message ‘%@’.”, [error localizedDescription]);
}

I want to access this file in Safari by giving the path of local file through the below code. 我想通过以下代码提供本地文件的路径,以在Safari中访问此文件。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:localFileURL] ];

Is it possible? 可能吗? I saw somewhere, we can use the URL starting with "file:///" . 我在某个地方看到了,我们可以使用以“ file:///”开头的URL。 Is it true? 是真的吗 If yes, how can i access my documents directory file path in Safari passing the URL via the above one line code? 如果是,我如何通过上面的一行代码通过URL访问Safari中的文档目录文件路径?

Please advise. 请指教。

Thank you! 谢谢!

I would expect that that is not possible because every app is sandboxed, which means your app's data is not accessible to any other app, and vice versa. 我希望这是不可能的,因为每个应用程序都被沙盒化,这意味着其他任何应用程序都无法访问您的应用程序数据,反之亦然。

To add to that, file:// is not one of the recognized or supported iOS schemes, as far as I know. 另外,据我所知, file://不是公认或受支持的iOS方案之一。

If what you mean is to run the html in a browser inside the app that LOOKS LIKE Safari, you can use a UIWebView and call 如果您的意思是在类似于Safari的应用程序内的浏览器中运行html,则可以使用UIWebView并调用

 loadHTMLString:baseURL 

You can create your file URL like this: 您可以这样创建文件URL:

 NSURL *myFileURL = [NSURL fileURLWithPath: pathToMyFile];

But like everyone else says, you can't access an app's file from any other app (without jailbreaking). 但是就像其他所有人所说的那样,您不能从任何其他应用程序访问应用程序的文件(无需越狱)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM