小智 8
不知道确切的问题是什么,但这里是我如何访问我的应用程序的本地文档文件夹(这不是您存储应用程序使用的源文件夹,但是您的应用程序存储本地资源的文件夹),例如,在我的应用程序中,我用相机拍摄照片并将它们存储到应用程序的本地文件夹,而不是设备相机胶卷,所以要获得我执行此操作的图像数量,在viewWillAppear方法中使用:
// create the route of localDocumentsFolder
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//first use the local documents folder
NSString *docsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];
//then use its bundle, indicating its path
NSString *bundleRoot = [[NSBundle bundleWithPath:docsPath] bundlePath];
//then get its content
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
// this counts the total of jpg images contained in the local document folder of the app
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.JPG'"]];
// in console tell me how many jpg do I have
NSLog(@"numero de fotos en total: %i", [onlyJPGs count]);
// ---------------
Run Code Online (Sandbox Code Playgroud)
如果你想知道文档文件夹中的内容(你可以在iOS模拟器中实际浏览的文件夹)
通过〜/ YourUserName/Library/Application Support/iPhone Simulator/versioOfSimulator/Applications/appFolder/Documents)
你会用NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];而不是.
希望它可以帮到你,交配!
| 归档时间: |
|
| 查看次数: |
5499 次 |
| 最近记录: |