How can i attach image file to my app mail in iOS - ios7

I have an app. On a click on the button I want the screen of the app should be captured and MailComposer window should be opened and the image captured previously should get attached to it. The mail sent but there is no attached image file
plz help me.
thank in advance...,
My code is here....
MFMailComposeViewController *controller =[[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"Screen shot maker"];
[controller setMessageBody:#"Hi , <br/> This is Screen Shot Maker" isHTML:YES];
[controller addAttachmentData:[NSData dataWithContentsOfFile:#"myScreenShot.png"] mimeType:#"png" fileName:#"myScreenShot.png"];
if (controller)
[self presentModalViewController:controller animated:YES];

Use below code:
UIGraphicsBeginImageContext(self.view.bounds.size);
// [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller addAttachmentData:data mimeType:#"application/image" fileName:#"Test.png"];
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
controller.modalPresentationStyle = UIModalPresentationFormSheet;
}
else
{
controller.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self presentModalViewController:controller animated:YES];

Related

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

UI issues while using blocks

I am using MBProgressHUD to display a loading indicator on my app. When i want to change something at UI or i open a new screen inside block, i only see a blank white screen. Does anyone has an idea what am i missing in my code?
-(void)doSomething:(id)sender
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Please wait";
[HUD showAnimated:YES whileExecutingBlock:^{
NSDictionary* dictReturn = [ServerApi getItemDetails::itemId userId:userId;
NewScreenController* vc = [[NewScreenController alloc]init];
[self presentViewController:vc animated:YES completion:nil];
}];
}
MBProgressHUD doesn't execute the block in the main thread. That's why you shouldn't change UI there at all.
You should use the method with a completionBlock instead.
- (void)doSomething:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Please wait";
dispatch_block_t executionBlock = ^{
self.dictReturn = [ServerApi getItemDetails:itemId userId:userId];
};
void (^completionBlock)() = ^{
NewScreenController *vc = [[NewScreenController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
};
[HUD showAnimated:YES
whileExecutingBlock:executionBlock
completionBlock:completionBlock];
}

didFinishPickingMediaWithInfo for two images

I have two image views named obsPic1 and obsPic2
They receive an image from picker/camera. This works fine for one image but any more and the images are the same. How do I do this for more than one image? Ive tried accessing the buttons sender tag but get undeclared identifier error, ive also tried using if statements. Whats the correct way to do this?
- (IBAction)addObsPhotoBtnPresssed:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self.editController presentModalViewController:imagePicker animated:YES];
//iPad
}
else {
if (self.pop) {
[self.pop dismissPopoverAnimated:YES];
}
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
self.obsPic1.backgroundColor = [UIColor whiteColor];
self.obsPic1.image = image;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *path = [ICUtils pathForDocument:#"obsPic.png"];
[imageData writeToFile:path atomically:NO];
UIImage *image2 = [info objectForKey:UIImagePickerControllerEditedImage];
self.obsPic2.backgroundColor = [UIColor whiteColor];
self.obsPic2.image = image2;
NSData *imageData2 = UIImagePNGRepresentation(image);
NSString *path2 = [ICUtils pathForDocument:#"obsPic2.png"];
[imageData2 writeToFile:path2 atomically:NO];
}
Both your image and image2 reference the same image:
[info objectForKey:UIImagePickerControllerEditedImage]
Are you perhaps looking to reference the Edited and Original images:
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
and
UIImage *image2 = [info objectForKey:UIImagePickerControllerOriginalImage];
or vice versa? If OTOH you're trying to allow for multiple image picking look into ELCImagePickerController

Display full camera in iPad

I am try to display full camera in iPad. but it displays very small camera. I am using below this code.
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate=self;
imagePicker.cameraOverlayView.frame = CGRectMake(0, 0, 1000, 700);
[imagePicker.cameraOverlayView sizeToFit];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
imagePicker.wantsFullScreenLayout = YES;
[imagePicker release];
[popover presentPopoverFromRect:CGRectMake(0,0,400,800)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
UIImagePickerController is a UINavigationController. Just show it as a full screen modal view controller instead of in a popover.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:ipc animated:YES completion:nil];
You only need to use a popover on the iPad for selecting images from the photo library. But the camera is allowed to be shown full screen without a popover.

How can I create unique PopoverView

How can I create special popOver?
I have manually created a new class, with needed design.
Then I want to load it like a PopOver
-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];
myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
But when I trying to tap the button, my app crashes with exc_bad_access
What`s wrong?
Use this code to create the popover
-(IBAction)Click_event
{ UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
{
Popview *pop = [[Popview alloc] initWithNibName:#"Popview" bundle:nil];
popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
[popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[popoverview dismissPopoverAnimated:YES];
}
}
Lets try this. It may be helpful for you
Try this way u may fix the issue....
PopimagepickerViewController.h
UIPopoverController *popoverController;
UIPopoverController *popoverimagview; // imagepicker popoverview
PopimagepickerViewController.m
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // Set the popoverview Width and height
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft //pooverview down direction
animated:YES];
[popoverView release];
[popoverContent release];
}
Your code seems overly complex, and non standard. I use this code to create a popover.
(I've edited this to match your case, but it's not tested)
-(void) buttonAction:(id) sender
{
UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[myThirdPop release];
}