问题
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).
Essentially, I'm asking if I can get the filenames of the photos stored on the iPhone or simulator.
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.
回答1:
You simply have to use the 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];
}
回答2:
This is something of a duplicate of a SO question asked already here - Get list of all photo albums and thumbnails for each album
From that answer: Take a look at AssetsLibrary framework.
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.
回答3:
Using this methods, you can easily implement that.
https://www.dropbox.com/sh/trmg44a93hwq35x/AACAVGY6VKEDR0tDUOqoxd-Ba?dl=0
来源:https://stackoverflow.com/questions/11319463/access-photo-library-via-objective-c-xcode-in-ios