i want attach multi photos to one mail for my application
with this code i can attach only the last one photos to mail but i can read all photos in uiimageview
how can attaching all photos to one mail ?
here is the codes for read image
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {
[self dismissModalViewControllerAnimated:YES];
////
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController * mailControler = [[MFMailComposeViewController alloc]init];
mailControler.mailComposeDelegate = self;
mailControler.modalPresentationStyle = UIModalPresentationFormSheet;
NSString *emailBody = #""; // optional
[mailControler setMessageBody:emailBody isHTML:YES];
for (UIView *v in [scrollview subviews]) {
[v removeFromSuperview];
}
CGRect workingFrame = scrollview.frame;
workingFrame.origin.x = 0;
for(NSDictionary *dict in info) {
imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[scrollview addSubview:imageview];
[imageview release];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
NSLog(#"image %#", imageview.image);
NSData * data = UIImageJPEGRepresentation(imageview.image, 0.0);
[mailControler addAttachmentData:data mimeType:#"image/jpeg" fileName:#"Photos"];
}
[scrollview setPagingEnabled:YES];
[scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
}
Part 2 go mail
-(IBAction)actionEmailComposer
{
[self presentViewController:mailControler animated:YES completion:nil];
}
the app is crashed
You've got a whole mess of code in there about obtaining your images and dealing with your UI that is irrelevant to the question (and quite possibly why your app is crashing -- doesn't look like it's crashing because of your MFMailComposeViewController interaction). How you're obtaining your images is very hard to follow without the context of your larger UI.
But to focus on just your core question: how do you attach multiple photos to one email?
Answer: call [mailControler addAttachmentData: mimeType: fileName: multiple times. You can call it as many times as you need, provided you don't send two items with the same filename.
Related
Hi I am very new to developing iOS application please help me. i am facing a problem regarding capturing image by using UIImagePicker. I have integrated hip mob app in to our application.
In that window i want to show a UIButton so that the user click on that UIButton should capture the image. when i click on the button its throwing an message as (whose view is not in the window hierarchy!).
I think this happens due to this chat window. here is my code snippet.!
[[HMService sharedService] openChat:self withSetup:^(HMChatViewController * controller)
{
controller.chatDelegate = self;
controller.chatView.receivedMessageFont = [UIFont systemFontOfSize:20.0];
controller.navigationBarHidden = YES;
UIView * viewObjForVehicleDetails = [[UIView alloc]init];
UIButton * btnForCaputrePhoto = [[UIButton alloc]init];
[btnForCaputrePhoto addTarget:self action:#selector(CapturePhotoImage) forControlEvents:UIControlEventTouchUpInside];
btnForCaputrePhoto.frame = CGRectMake(55, 90, 103, 85);
[controller.chatView addSubview:viewObjForVehicleDetails];
[viewObjForVehicleDetails addSubview:btnForCaputrePhoto];
[[controller.chatView table] registerClass:[ChatTableViewCell class] forCellReuseIdentifier:#"ReuseChatTableViewCell"];
}
-(void)CapturePhotoImage
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:NO completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Thanks in Advance.!
First be sure you are using the following delegate in your view controller
<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
Secondly use this line to show the ImagePicker:-
[self presentModalViewController:picker animated:YES];
Alternative Way:-
[self.view addSubview:imagePicker.cameraOverlayView]
Change the method declaration as follows
- (IBAction) CapturePhotoImage:(id)sender
{
NSLog("Called");
}
And the method call "CapturePhotoImage" as CapturePhotoImage:
[btnForCaputrePhoto addTarget:self action:#selector(CapturePhotoImage:) forControlEvents:UIControlEventTouchUpInside];
I am using iCarousel custom control to show image from web that consumed with JSON data.
Here is my codes to show image in iCarousel
to Load JSON Data in ViewDidLoad
JSONLoader *jsonLoader = [[JSONLoader alloc]init];
self.items = [[NSMutableArray alloc]init];
[self.items removeAllObjects];
self.items = (NSMutableArray *) [jsonLoader loadJSONDataFromURL:[NSURL URLWithString:#"https://public-api.wordpress.com/rest/v1/sites/www.myWebsite.com/posts?category=blog&page=1"]];
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(AsyncImageView *)view
{
MMSPLoader *mmObject = [self.items objectAtIndex:index];
view = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, 250.0f, 250.0f)];
view.layer.borderColor = [UIColor whiteColor].CGColor;
view.layer.borderWidth = 0.3f;
view.image=[UIImage imageNamed:#"page.png"];
view.imageURL = [NSURL URLWithString:[mmObject featureImageUrl]];
return view;
}
That can show image correctly. My case is when i tap on that image , i want to show that image in FULL SCREEN. So i used GGFullScreenImageViewController.
However when i tap on that Image to show FULL SCREEN , i retrieved Image URL and show in GGFullScreenImageViewController. It's fine but , i don't want to retrieve from that URL because it downloading image from web again and slowing to show.
In my idea , i saved that image when tap on image in iCarousel and show it in GGFullScreenImageViewController.
So i don't need to download image again.
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
dispatch_queue_t myqueue = dispatch_queue_create("com.i.longrunningfunctionMain", NULL);
dispatch_async(myqueue, ^{
UIApplication *apps = [UIApplication sharedApplication];
apps.networkActivityIndicatorVisible = YES;
MMLoader *mmObject = [self.items objectAtIndex:index];
NSData *data = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mmObject.featureImageUrl]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]];
GGFullscreenImageViewController *vc = [[GGFullscreenImageViewController alloc] init];
vc.liftedImageView = imageView;
dispatch_async(dispatch_get_main_queue(), ^{
apps.networkActivityIndicatorVisible = NO;
[self presentViewController:vc animated:YES completion:nil];
});
});
NSLog(#"%i",index);
}
So should i save to local file or is there any others nice idea?
Really you should use a library to save the image when you initially download it. AsyncImageView isn't necessarily the best choice as it just caches in memory.
That said, at the moment you can just get the image from the view. This isn't ideal, and you should save it to disk - just sooner rather than later. Look at, perhaps, SDWebImage for that.
To get the image from the view (typed in browser so verify syntax and API usage...):
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
AsyncImageView *view = (AsyncImageView *)[carousel itemViewAtIndex:index];
UIImageView *imageView = [[UIImageView alloc] initWithImage:view.image];
GGFullscreenImageViewController *vc = [[GGFullscreenImageViewController alloc] init];
vc.liftedImageView = imageView;
[self presentViewController:vc animated:YES completion:nil];
}
I am making an app for iPhone and want to give users the ability to multiselect images from their photo-library. I already have a working code for user to select four images at a time.
But I can't select 1 or 2 or 3 images at a time. I want to select the 1 or 2 or 3 images at a time.
This is my code. I have struggled for 3 days without finding a solution. Please help me anybody.
Thanks in advance.............
-(void)choosePhotoFromExistingImages
{
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.navigationController dismissViewControllerAnimated: YES completion: nil];
}
- (void)displayPickerForGroup:(ALAssetsGroup *)group
{
ELCAssetTablePicker *tablePicker = [[ELCAssetTablePicker alloc] initWithStyle:UITableViewStylePlain];
tablePicker.singleSelection = YES;
tablePicker.immediateReturn = YES;
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:tablePicker];
elcPicker.maximumImagesCount = 0;
elcPicker.imagePickerDelegate = self;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
tablePicker.parent = elcPicker;
// Move me
tablePicker.assetGroup = group;
[tablePicker.assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];
[self presentViewController:elcPicker animated:YES completion:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
}
#pragma mark ELCImagePickerControllerDelegate Methods
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
CGRect workingFrame = _scrollView.frame;
workingFrame.origin.x = 0;
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info)
{
UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.view addSubview:imageview ];
self.chosenImages = images;
}
UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(10, 240, 40, 40)];
image1.image=[images objectAtIndex:0];
[self.view addSubview:image1];
UIImageView *image2=[[UIImageView alloc]initWithFrame:CGRectMake(60, 240, 40, 40)];
image2.image=[images objectAtIndex:1];
[self.view addSubview:image2];
UIImageView *image3=[[UIImageView alloc]initWithFrame:CGRectMake(120, 240, 40, 40)];
image3.image=[images objectAtIndex:2];
[self.view addSubview:image3];
UIImageView *image4=[[UIImageView alloc]initWithFrame:CGRectMake(180, 240, 40, 40)];
image4.image=[images objectAtIndex:3];
[self.view addSubview:image4];
}
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Here is the link for the Tutorial. Its works fine in my project.Try this
Hope its useful for you.
Check your code in - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
For example, you create array with length of 2, but in code below you try to get image3.image=[images objectAtIndex:2]; and image4.image=[images objectAtIndex:3];. It's not a surprise that your code throws exception.
Good luck!
i have two ViewControllers, when i tap a cell i need to open other viewController and see image (image with names 1, 2, 3,...._full.jpg), so i write:
DetailViewController *dvc = [[DetailViewController alloc] init];
[dvc updateImage:[NSString stringWithFormat:#"%d", indexPath.row]];
[self.navigationController pushViewController:dvc animated:YES];
in my dvc
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
self.image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];
[self.image setTag:1];
[self.view addSubview:self.image];
}
method what i called
-(void)updateImage:(NSString*)imageName
{
[(UIImageView*)[self.view viewWithTag:1] setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#_full.jpg", imageName]]];
}
smth like self.image.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#_full.jpg", imageName]]; didn't work for me.
so, these code works fine in my IOS 5,6,7 emulators, but when i compile it on my IPad 2, IOS 5.1 my image is not updating, all i see is gray background.
What am i doing wrong?
You run
[dvc updateImage:[NSString stringWithFormat:#"%d", indexPath.row]];
After that viewDidLoad is called and your image is reseted.
Instead that pass image name as a string
[dvc setImageName:[NSString stringWithFormat:#"%d", indexPath.row]];
and in DetailViewController.m in viewDidLoad call
[self updateImage:[NSString stringWithFormat:#"%#_full.jpg", self.imageName]];
Remember to add #property imageName to your DetailViewController.h file.
omg, XCode is joking, it's all because of my images where not ".jpg" they where ".JPG"!. I'm angry...
I want to open iphone saved images in my application. my application working in landscape mode. when I trying to load all saved photo from iphone library using presentModalViewController method, it will open in portrait mode. I want that in landscape mode. here is the code:
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.allowsEditing = NO;
picker.navigationBarHidden = YES;
picker.wantsFullScreenLayout = YES;
[picker setNavigationBarHidden:TRUE];
[self presentModalViewController:picker animated:NO];
NSLog(#"%#", self.view.subviews);
[picker release];
can any one help me..
Thanks in advance.
You can't. Quoth the documentation:
The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing.
It's a bit more work, but you can use the AssetsLibrary framework to access the list of images and create your own image picker.
we cant get UIImagePickerController in landscape...
but we can get the images in our device into an array and display them in landscape mode and in portrait mode....itseems same like UIImagePickerController...
we should use ALAsset class and ALAssetsLibrary for this..
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != NULL)
{
[assets addObject:result];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self meth];
[activity stopAnimating];
[activity setHidden:YES];
};
assets = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) { NSLog(#"Failure");}];
in viewDidLoad
-(void)meth
{
NSLog(#"%i",[assets count]);
if(userOrientation==UIInterfaceOrientationPortrait || userOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(#"haii");
[scrollView removeFromSuperview];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor=[UIColor whiteColor];
NSLog(#"%i",[assets count]);
for (int i = 0; i < [assets count]; i++)
{
imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[imgBtn setFrame:CGRectMake((i%4*80)+2,(i/4*80)+2,75,75)];
imgBtn.tag=i;
[imgBtn addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
ALAsset *asset=[assets objectAtIndex:i];
[imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal];
[scrollView addSubview:imgBtn];
}
scrollView.contentSize = CGSizeMake(320,(([assets count]/4)+1)*300 );
}
if(userOrientation==UIInterfaceOrientationLandscapeRight || userOrientation==UIInterfaceOrientationLandscapeLeft)
{
[scrollView removeFromSuperview];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 480,320)];
for (int i = 0; i < [assets count]; i++)
{
imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[imgBtn setFrame:CGRectMake((i%6*80)+2,(i/6*80)+2,75,75)];
imgBtn.tag=i;
[imgBtn addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
ALAsset *asset=[assets objectAtIndex:i];
[imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal];
[scrollView addSubview:imgBtn];
}
scrollView.contentSize = CGSizeMake(480,(([assets count]/4)+1)*300);
}
[self.view addSubview:scrollView];
}
I have tried the code with some additions
[self.navigationController setNavigationBarHidden:YES];
[self addChildViewController:picker];
[self.view addSubview:picker.view];
picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
picker.view.frame = self.view.bounds;
[picker didMoveToParentViewController:self];
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker.view removeFromSuperview];
[picker removeFromParentViewController];
}
(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker.view removeFromSuperview];
[picker removeFromParentViewController];
}
I used following code:
[self.view addSubview:imgPicker.view];
[imgPicker viewWillAppear:YES];
[imgPicker viewDidAppear:YES];
instead of using presentModalViewController method,
[self presentModalViewController:picker animated:NO];
I tried this approach, while following the API docs more closely:
- (void)openEmbeddedImagePicker:(UIImagePickerController *)picker {
[self.navigationController setNavigationBarHidden:YES];
[self addChildViewController:picker];
[self.view addSubview:picker.view];
picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
picker.view.frame = self.view.bounds;
[picker didMoveToParentViewController:self];
}
But the video recorder's Cancel and playback buttons don't respond. Also, while the containing VC (self in the above method) restricts the orientation to landscape, rotating between the two landscape modes messes up the layout of the picker's overlay bar (on iOS 6, at least).
Does anyone have success restricting the video recorder to landscape mode?
From the UIImagePickerController Class Reference.
Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.