在 iOS 中通过 Objective-C/Xcode 访问照片库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11319463/
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
Access Photo Library via Objective-C/Xcode in iOS
提问by Objc55
I'm writing an iPhone application. I'm wondering if I can get a list of files/filenames of the photos stored in the iPhone library (or those in the simulator).
我正在编写一个 iPhone 应用程序。我想知道是否可以获得存储在 iPhone 库(或模拟器中的照片)的文件/文件名列表。
Essentially, I'm asking if I can get the filenames of the photos stored on the iPhone or simulator.
本质上,我是在问我是否可以获取存储在 iPhone 或模拟器上的照片的文件名。
I appreciate any help, thanks!
我感谢任何帮助,谢谢!
EDIT:
编辑:
image = [UIImage imageNamed:@"/Users/Library/Application Support/iPhone Simulator/5.0/Media/DCIM/100APPLE/IMG_0002.jpg"];
imageView.image = image;
doesn't work, unfortunately.
不幸的是,不起作用。
回答by Vinestro
You simply have to use the UIImagePickerController
.
您只需使用UIImagePickerController
.
It gives something like that:
它给出了这样的东西:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
// Don't forget to add UIImagePickerControllerDelegate in your .h
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
回答by Matt S.
This is something of a duplicate of a SO question asked already here - Get list of all photo albums and thumbnails for each album
这是这里已经提出的 SO 问题的重复 -获取每个相册的所有相册和缩略图的列表
From that answer: Take a look at AssetsLibraryframework.
从那个答案:看看AssetsLibrary框架。
Note that if you have access to the iOS 6 Beta, you'll want to note the changes taking place for accessing those assets. Can say no more per NDA.
请注意,如果您有权访问 iOS 6 Beta,则需要注意访问这些资产所发生的更改。每个 NDA 不能再说了。
回答by Chigs79
Using this methods, you can easily implement that.
使用这些方法,您可以轻松实现。
https://www.dropbox.com/sh/trmg44a93hwq35x/AACAVGY6VKEDR0tDUOqoxd-Ba?dl=0
https://www.dropbox.com/sh/trmg44a93hwq35x/AACAVGY6VKEDR0tDUOqoxd-Ba?dl=0