objective-c 如何访问 iPhone 应用程序目录并将图像文件存储在那里
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/516215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access iPhone application directory and store image files there
提问by Neo
I want to know whether I can access the directory where my application is installed. Also I want to create a sub directory in the same directory to store all the images I capture in my application. I further want to view the images using iPhone's default image viewer. Can this be done?
我想知道我是否可以访问安装我的应用程序的目录。此外,我想在同一目录中创建一个子目录来存储我在应用程序中捕获的所有图像。我还想使用 iPhone 的默认图像查看器查看图像。这能做到吗?
回答by pjb3
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"App Directory is: %@", appFolderPath);
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);
回答by Girish Kolari
You can get the Document folder of the app
您可以获取应用程序的文档文件夹
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
You can create Folder and files using NSFileManger. You can store files in document folder or even you can store it in temp folder.
您可以使用 NSFileManger 创建文件夹和文件。您可以将文件存储在文档文件夹中,甚至可以将其存储在临时文件夹中。
回答by ingh.am
If you want to access the app on the simulator, navigate to this directory:
如果要访问模拟器上的应用程序,请导航到此目录:
~/Library/Application Support/iPhone Simulator/User/Applications
~/库/应用程序支持/iPhone 模拟器/用户/应用程序
If you want to access the app on a device it gets a little trickier. First, plug your iOS device into iTunes and backup the phone (with encryption turned off). Then download this app: iPhone / iPod Touch Backup Extractor, find your bundle ID and click extract. The app will then get all the data for you to see. Sure it's not real time but does the job!
如果您想在设备上访问该应用程序,它会变得有点棘手。首先,将您的 iOS 设备插入 iTunes 并备份手机(关闭加密)。然后下载此应用程序:iPhone / iPod Touch Backup Extractor,找到您的捆绑 ID 并单击提取。然后,该应用程序将获取所有数据供您查看。当然这不是实时的,但可以完成工作!
回答by BeNice
回答by Plumenator
To store any files of your own, you'll have to use the Documents directory as Girish already said. But if you need to display images that you captured using the camera, the only way you can display them with UIImagePickerController (the default image viewer) is by specifying the source type when initializing it as the saved photos album.
要存储您自己的任何文件,您必须使用 Girish 已经说过的 Documents 目录。但是,如果您需要显示使用相机拍摄的图像,则可以使用 UIImagePickerController(默认图像查看器)显示它们的唯一方法是在将其初始化为保存的相册时指定源类型。
回答by August
C'mon, this is all in the sample code and documentation. In fact, it's even one of the Frequently Asked Questions in the iPhone Dev Center. I refuse to give the answer. Instead, here's a link: Easily found documentation that answers your question
来吧,这都在示例代码和文档中。事实上,它甚至是 iPhone 开发中心的常见问题之一。我拒绝给出答案。相反,这里有一个链接: 轻松找到可以回答您问题的文档

