XCode 4 - 轻松访问安装在模拟器上的应用程序的“文档”文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11413847/
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
XCode 4 - Easily access "Documents" folder of an app installed onto the simulator
提问by Oliver
When running an app onto the simulator, it creates a folder onto the Mac to contain the apps datas in a "Documents" folder. This folder is changed when you delete the app from the simulator, or when you change some app settings into XCode. When you have dozens of apps, it's a nightmare to find the good one by hand.
在模拟器上运行应用程序时,它会在 Mac 上创建一个文件夹,以在“文档”文件夹中包含应用程序数据。当您从模拟器中删除应用程序或将某些应用程序设置更改为 XCode 时,此文件夹会更改。当您拥有数十个应用程序时,手动找到好的应用程序是一场噩梦。
Is there a way to easily access this folder ?
有没有办法轻松访问此文件夹?
回答by Bazinga
Just gonna try answering. How about logging it, like this:
只是想尝试回答。如何记录它,像这样:
//App Directory & Directory Contents
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"App Directory is: %@", appFolderPath);
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);
回答by spring
What I do is create a link in the Finder sidebar to the simulator folder. It is approximately:
我所做的是在 Finder 侧栏中创建一个指向模拟器文件夹的链接。它大约是:
/Users/userName/Library/Application/Support/iPhone/Simulator/5.0/Applications/
/Users/userName/Library/Application/Support/iPhone/Simulator/5.0/Applications/
Then I have that folder sorted by 'last modified'. Once I find the app folder for the app I am working on, I expand it to display the app (and see the app name) and also set a color on the folder. The Finder sometimes doesn't keep the folder sorted by 'last modified' unless the window is closed and reopened.
然后我将该文件夹按“上次修改时间”排序。找到我正在处理的应用程序的应用程序文件夹后,我将其展开以显示该应用程序(并查看应用程序名称)并在该文件夹上设置颜色。Finder 有时不会按“上次修改时间”对文件夹进行排序,除非窗口关闭并重新打开。
回答by us_david
The location in general is:
/Users/yourusername/Library/Application Support/iPhone Simulator/7.1/Applications/appcode/Documents/yourdocuments.db
位置一般是:
/Users/yourusername/Library/Application Support/iPhone Simulator/7.1/Applications/appcode/Documents/yourdocuments.db
'yourusername': username you used for your development machine
'appcode': application identifier that is a series of numbers such as: 32F88907-B348-4764-9819-A5B6F9169FB7 (unique to your app)
‘yourusername’:您用于开发机器
的用户名‘appcode’:应用程序标识符,是一系列数字,例如:32F88907-B348-4764-9819-A5B6F9169FB7(您的应用程序独有)
the version number (7.1) in the path depends on the version of Xcode and hence the simulator.
路径中的版本号 (7.1) 取决于 Xcode 的版本,因此取决于模拟器。
回答by sebrenner
directoryContentsAtPath: is deprecated.
directoryContentsAtPath:已弃用。
Instead use contentsOfDirectoryAtPath:error:
而是使用 contentsOfDirectoryAtPath:error:
//App Directory & Directory Contents
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"App Directory is: %@", appFolderPath);
NSLog(@"Directory Contents:\n%@", [fileManager contentsOfDirectoryAtPath:appFolderPath error:nil]);
回答by Jari Kein?nen
Bazinga's answer(along with sebrenner's deprecation notice) is great for Objective-C.
Bazinga 的回答(以及sebrenner 的弃用通知)非常适合 Objective-C。
For Swift, the equivalent would be:
对于 Swift,相当于:
let appFolderPath = NSBundle.mainBundle().resourcePath
let fileManager = NSFileManager.defaultManager()
print("App Directory is: \(appFolderPath)")
print("Directory Contents:\n \(fileManager.contentsAtPath(appFolderPath!))")