I am using CTAssetsPickerController https://github.com/chiunam/CTAssetsPickerController to import images from the photos app. I want to disable importing from the 'Hidden' album some users may have. If you have What's App and a hidden album you'll notice that you can't import from said album. I want to be able to do the same but been searching for hours and haven't gotten anywhere yet. Appreciate your help
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType {
// Create the image picker
// request authorization status
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
dispatch_async(dispatch_get_main_queue(), ^{
// init picker
self.imagePickerController = [[CTAssetsPickerController alloc] init];
// set delegate
self.imagePickerController.delegate = self;
// create options for fetching photo only
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:#"mediaType == %d", PHAssetMediaTypeImage];
// assign options
self.imagePickerController.assetsFetchOptions = fetchOptions;
// Optionally present picker as a form sheet on iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
self.imagePickerController.modalPresentationStyle = UIModalPresentationFormSheet;
// present picker
[self presentViewController:self.imagePickerController animated:YES completion:nil];
});
}];
Looking at the repo for CTAssetsPickerController, it seems you can set the album type by setting a property called assetCollectionSubtype to an array of integer values, corresponding to Apple's PHAssetCollectionSubtype enum. https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAssetCollection_Class/#//apple_ref/c/tdef/PHAssetCollectionSubtype
So after a little more research I found that the framework has a delegate method that enables you to disable assets.
To solve my problem I implemented this method:
- (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldEnableAsset:(PHAsset *)asset {
return !asset.isHidden;
}
The hidden album still shows up but importing from it is disabled.
Related
I'm using ELCImagePickerController in my project. Select multiple images from the gallery through it. I'm facing an issue that , how i can show the selected multiple images in an image view in a view controller. I have created a select image button which take us to photolibrary where we select multiple images.My code is,
- (IBAction)Select:(id)sender {
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 100; //Set the maximum number of images to select to 100
elcPicker.returnsOriginalImage = YES; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return asset location information
elcPicker.onOrder = YES; //For multiple image selection, display and return order of selected images
// elcPicker.mediaTypes = #[(NSString *)kUTTypeImage, (NSString
*)kUTTypeMovie]; //Supports image and movie types
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}
- (void)elcImagePickerController:(ELCImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
for (NSDictionary *dict in info)
{
if ([dict objectForKey:UIImagePickerControllerMediaType] ==
ALAssetTypePhoto)
{
if ([dict objectForKey:UIImagePickerControllerOriginalImage])
{
UIImage* image=[dict
objectForKey:UIImagePickerControllerOriginalImage];
_arrimage.image;
}
}
}
}
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
You can use CreolePhotoSelection to get and select multiple images. It will help to you gets multiple selection and retrieve all selected value into delegate method.
Below is the sample code for it:
CreolePhotoSelection *objCreolePhotoSelection= [[CreolePhotoSelection alloc] initWithNibName:#"CreolePhotoSelection" bundle:nil];
objCreolePhotoSelection.strTitle = YOUR_TITLE_FOR_PHOTO_VIEW;
objCreolePhotoSelection.delegate = self; // It will help to retrive all selected photos from CreolePhotoSelection
objCreolePhotoSelection.arySelectedPhoto = YOUR_CURRENT_ARRAY; // You need to pass same array which is holding selected image
objCreolePhotoSelection.maxCount = YOUR_MAX_PHOTOS_LIMIT; // Eg. 5, 10 anythings...
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:objCreolePhotoSelection];
[self.navigationController presentViewController:navController animated:YES completion:nil];
// Delegate Method
#pragma mark - Photo selected Delegate Method
-(void)getSelectedPhoto:(NSMutableArray *)aryPhoto
{
// You will selected image array into aryPhoto object and you can use it
}
First of all an Image View is to show a single image. From the piece of code you shared I am not clear what did you mean by
UIImage* image=[dict
objectForKey:UIImagePickerControllerOriginalImage];
_arrimage.image;
What does this _arrimage mean? Is that a reference to the Image view? then it should be
_arrimage.image = image; //the image fetched in the above line
But this won't fix your issue as this will show only the very last object found in the for loop (probably the last selected image).
To show all selected images it is better to go with a collection view with the array of images as the data source and load each images in each cells of the collection view.
If you want to show all images within the same image view, there is another option by setting it as animationimages
imageView.animationImages = imagesListArray //the list of image you selected
imageView.animationDuration = 2.0
imageView.startAnimating()
This just show each images one at a time from the array with a time interval of 2 seconds
You can't Show Multiple Images in a single ImageView at a same time but yes you can show multiple images on a same ImageView for sometime using Image Animation.
var imagesArray = [UIImage]()
for imageName in 1...3
{
imagesArray.append(UIImage(named: "\(imageName).png")!)
}
// You can also use below code to add images if not want to use loop
// imagesArray.append(UIImage(named: "a.png")!)
// imagesArray.append(UIImage(named: "b.png")!)
// imagesArray.append(UIImage(named: "c.png")!)
self.imageView.animationImages = imagesArray
self.imageView.animationDuration = 2.0
self.imageView.startAnimating()
I'm using UIImagePickerController in my applicaiton.
I'm showing the following alert in button action.
My code looks like the following in alertview delegate method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView.title isEqualToString:#"Choose"]) {
if (buttonIndex == 1) { //Camera
[self presentImagePickerControllerWithCamera:YES];
}
else if(buttonIndex == 2) { //Library
[self presentImagePickerControllerWithCamera:NO];
}
}
}
and the content of the method 'presentImagePickerControllerWithCamera' is:
- (void)presentImagePickerControllerWithCamera:(BOOL)isCamera {
CFStringRef mTypes[2] = { kUTTypeImage, kUTTypeMovie };
CFArrayRef mTypesArray = CFArrayCreate(CFAllocatorGetDefault(), (const void**)mTypes, 2, &kCFTypeArrayCallBacks);
imagePickerController.mediaTypes = (__bridge NSArray*)mTypesArray;
imagePickerController.videoMaximumDuration = 60.0f;
CFRelease(mTypesArray);
if (isCamera) { // Showing the camera (Both Camera and video)
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
imagePickerController.allowsEditing = NO;
}
else { // Showing library (Both Pictures and videos)
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:imagePickerController animated:YES completion:nil];
}
Here i need to limit the video to 1 min when user is selecting video from library, so i wrote
imagePickerController.videoMaximumDuration = 60.0f;
and
imagePickerController.allowsEditing = YES;
it's working fine. But When the user selects a picture from library i don't want editing(the square box on picture).
Is there any way to achieve it?
Any suggestions would be appreciated.
Thanks in advance.
This isn't possible with your current code.
You've assigned both the media types together. That will show you both image& video in to photo gallery. Once UIImagePickerController will show you'll not have access to it, I mean you can't know what user will select (an image or a video) before delegate get call.
So to achieve this with your case, you've to set each media type at once. And based on that media type, have to set allowsEditing property.
I need your help/references/hints on how to get a pictures from 1) my Gallery in iPhone and 2)from the iPhone front camera. So that my program copies this picture to its local folder on iPhone (not just referencing to Gallery). Thanks
You might find the info on this appple developer doc useful. You use UIImagePickerController to present a modal view, as shown in the code below, from the doc above.
- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Displays saved pictures and movies, if both are available, from the
// Camera Roll album.
mediaUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeSavedPhotosAlbum];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
mediaUI.allowsEditing = NO;
mediaUI.delegate = delegate;
[controller presentModalViewController: mediaUI animated: YES];
return YES;
}
I do suggest you read through the doc above, as it is very informative but not easily paraphrasable.
Hope this helps!
Iphone app, IOS 5 and up.
There are similar questions to this one on SO but I haven't encountered this exact scenario so I'll ask. I'm editing an existing app that allows lets you take a photo which it resizes and sends to a web service.
I need to add the ability to take 3 photos, resize each and send to the same service. I thought it would be just a matter of repeating what was already in the app but it uses the UIImagePickerController which apparently only allows one photo per use.
So the way it works is that there's a 'Take Photo' button which calls the method below. Once that photo is taken another button appears that says 'Take another photo' (I added this button) and I have it calling the same method but it is just copying over the previous photo, which is to be expected really. How should I best alter this to accommodate 3 photos?
This is the takephoto method that I'm calling.
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
check this https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html
, check the take photo part of this demo project.
Eventually figured out how to do this. I added a tag to the button calling the method, through IB.
Then in the takephoto method I assigned the imagePickerController a tag based on the tag of the button that tapped. Like this:
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if([sender tag] == 2)
{
imagePickerController.view.tag = 2;
}
//And so on...
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
Then in the ImagePickerController didFinishedPickingMediaWithInfo method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if(picker.view.tag == 2)
{
//Do stuff here
}
}
So, I'll probably have to create three different buttons for each of the three possible photos, I'm sure there's a better way than that but it should work.
I am trying to implement a feature of taking X amount of pictures programmatically after entering a UIViewController for both the iPhone and iPad. I looked into UIImagePickerController but I do not want to present the camera controls and have the user hit a button to capture only one photo. Is there a way to capture X amount of photos once entering a UIViewController and storing all the photos in the end for future reference in one go?
Edit:
-(void)viewDidAppear:(BOOL)animated
{
// Create image picker controller
picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
// Set source to the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
picker.delegate = self;
// Allow editing of image ?
picker.allowsEditing = NO;
//picker.showsCameraControls = NO;
// Show image picker
[picker animated:YES completion:nil];
}
straight away with takePicture you can not take multiple snaps, for that you have to use some video recording and get snap out of it for particular frame or time, for you more reference you can use this apple documentation for bulk snaps AVFoundation Programming Guide
You can try something like this:
int numberOfPhotos = 3; // Number of photos you want to take.
for ( int i = 0; i < numberOhPhotos; i++ )
{
// Note that you should use some sort of a pause in between each photo.
[picker takePicture];
}