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

2023-03-23移动开发问题
23

本文介绍了如何隐藏在 ios 的文档目录中创建的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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];

我可以在 Devices Document 文件夹中看到该文件.

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.

谁能帮我做这件事.

推荐答案

存储私有数据的好地方是~/Library/Application Support/,这是Mac上使用的文件夹这个目的.

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];
}

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

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

这篇关于如何隐藏在 ios 的文档目录中创建的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7