如何隐藏在ios文档目录中创建的文件夹?

发布于 2025-01-04 02:01:27 字数 546 浏览 2 评论 0原文

我以编程方式创建了一些 PDF 文件,我使用以下代码将其存储到设备内存中>>>>>

    NSString *fileName = [NSString stringWithFormat:@"SampleTextFile.pdf",strFinalString];

    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *saveDirectory = [path objectAtIndex:0];
    NSString *saveFileName = fileName;
    NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];

我可以在设备文档文件夹中看到该文件。

我想隐藏这些文件,以便用户无法看到或删除它。

任何人都可以帮我做到这一点。

I have created some PDF files programatically, which i am storing into the devices memory using the following code >>>>

    NSString *fileName = [NSString stringWithFormat:@"SampleTextFile.pdf",strFinalString];

    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *saveDirectory = [path objectAtIndex:0];
    NSString *saveFileName = fileName;
    NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];

I can see the file in the Devices Document folder.

I want to hide these files so that the user can not see or delete it.

Can anyone help me out to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂牵梦绕锁你心扉 2025-01-11 02:01:27

存储私人数据的好地方是 ~/Library/Application Support/,这是 Mac 上用于此目的的文件夹。

您可以使用以下方法生成此文件夹的路径:

NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];

您必须在第一次使用它时自己创建该文件夹,您可以这样做:

if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportDir])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:appSupportDir withIntermediateDirectories:YES attributes:nil error:NULL];
}

我编写了一个简单的库,使该文件夹和所有其他有用的 iOS 文件夹可作为方法使用NSFileManager: https://github.com/nicklockwood/StandardPaths

A good place to store private data is in ~/Library/Application Support/, which is the folder used on the Mac for this purpose.

You can generate a path to this folder using:

NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];

You'll have to create the folder yourself the first time you use it, which you can do with:

if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportDir])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:appSupportDir withIntermediateDirectories:YES attributes:nil error:NULL];
}

I wrote a simple library that makes this and all other useful iOS folders available as methods on NSFileManager: https://github.com/nicklockwood/StandardPaths

阳光下的泡沫是彩色的 2025-01-11 02:01:27

只需在文件名前面加上一个点,如 .SampleTextFile.pdf 中所示。

但真正的解决方案是首先不将文档存储在 NSDocumentDirectory 中。您应该在 NSLibraryDirectory 中创建子目录并将这些内容存储在那里。它还会得到备份,不会像 Cachestmp 那样被清除,但用户无法使用 iTunes 访问它。

Just prefix the filename with a dot, as in .SampleTextFile.pdf.

But the real solution is to not store the document in the NSDocumentDirectory in the first place. You should create subdirectory in the NSLibraryDirectory and store this stuff there. It also gets backed up and will not get purged like Caches and tmp, but the user cannot access it with iTunes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文