使用C/C ++在iOS中写入文件 [英] Writing to file in iOS using C/C++

查看:205
本文介绍了使用C/C ++在iOS中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在iOS中使用C/C ++调用来创建文本文件?然后可以从应用程序外部打开和读取文件吗?也就是说,应用程序A在它有权写入的地方创建一个文本文件,然后应用程序B从中读取文本文件.或者,忘记应用程序B,我可以打开它并阅读吗?

Is it possible to create a text file using C/C++ calls in iOS? Is it then possible to open and read the file from outside the application? That is, application A creates a text file somewhere it has permissions to write to and application B then reads from it. Or, forget application B, can I just open it and read?

推荐答案

是.

使用NSFileHandle获得对文件的读/写访问权限,并使用NSFileManager创建目录并列出目录内容,并进行所有其他类型的文件系统访问.

Use NSFileHandle to get read/write access to files and NSFileManager to create directories and list their contents and do all other sorts of file system access.

请记住,每个应用程序都是沙盒化的,只能写入其自己的指定目录.您可以使用以下代码获取这些目录的路径:

Just keep in mind that every App is sandboxed and can only write to its own designated directories. You can get the path to these directories with code like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

但是,您不能访问另一个应用程序的文件.

However, you can not access files of another App.

iTunes自动备份这些目录,因此,如果用户进行设备还原,它们将自动还原.另外请记住,您不应以文件浏览器或保存对话框"等形式将文件系统暴露"给App用户.

iTunes automatically backs up these directories, so they are automatically restored if the user does a device restore. Also keep in mind that you should not "expose" the file system to the App users in form of file-browsers or "save dialogs", etc.

这篇关于使用C/C ++在iOS中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆