Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-20-2011, 04:55 AM   #1 (permalink)
Registered Member
 
tobyaherbert's Avatar
 
Join Date: Nov 2010
Posts: 19
tobyaherbert is on a distinguished road
Post MFMailComposer Picture Attachment From Camera

Hello Everyone!
I am trying to email a photograph that i took with the camera or selected from the camera library. Does anyone know how to do this?

Here is my code:

.h
Code:
UIImageView * theimageView;
	UIButton * choosePhoto;
	UIButton * takePhoto;
}

@property (nonatomic, retain) IBOutlet UIImageView * theimageView;
@property (nonatomic, retain) IBOutlet UIButton * choosePhoto;
@property (nonatomic, retain) IBOutlet UIButton * takePhoto;

-(IBAction) getPhoto:(id) sender;
.m
Code:
-(IBAction) getPhoto:(id) sender {
	UIImagePickerController * picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	
	if((UIButton *) sender == choosePhoto) {
		picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
	} else {
		picker.sourceType = UIImagePickerControllerSourceTypeCamera;
	}
	
	[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
	[picker dismissModalViewControllerAnimated:YES];
	theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
	
	NSLog(@"Creating Mail Data!!!");
	NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1);
	MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
	[mailPicker addAttachmentData:photoData mimeType:@"image/jpg" fileName:[UIImage imageNamed:theimageView.image]];
	[mailPicker setSubject:@"Chicken Photograph!"];
	[mailPicker setToRecipients:[NSArray arrayWithObject:@"tobyherbert@syn-apps.co.uk"]];
	[mailPicker setDelegate:self];
	[self presentModalViewController:mailPicker animated:YES];
}
i can't seem to get it to accept the image view's image or the objectFoKey.
Thanks in advance
Toby......
tobyaherbert is offline   Reply With Quote
Old 02-20-2011, 09:43 AM   #2 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

I think the better thing to do is set the imageview's image from the method, dismiss the imagepicker, and then perform a void method after 0.5 seconds of the pickerview dismissing which would present the mailcomposer.

Code:
- (void)imagePickerController:(UIImagePickerController *)pickers didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
Here is my code that I am using in a current project:

Code:
- (void)imagePickerController:(UIImagePickerController *)pickers didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
	selectedImage = [image retain];
	[picker dismissModalViewControllerAnimated:YES];
	[self performSelector:@selector(showUploadImage) withObject:nil afterDelay:0.5];
}
iSDK is offline   Reply With Quote
Old 02-20-2011, 10:18 AM   #3 (permalink)
Registered Member
 
tobyaherbert's Avatar
 
Join Date: Nov 2010
Posts: 19
tobyaherbert is on a distinguished road
Post Camera MFMailComposer

Quote:
Originally Posted by iSDK View Post
I think the better thing to do is set the imageview's image from the method, dismiss the imagepicker, and then perform a void method after 0.5 seconds of the pickerview dismissing which would present the mailcomposer.

Code:
- (void)imagePickerController:(UIImagePickerController *)pickers didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
Here is my code that I am using in a current project:

Code:
- (void)imagePickerController:(UIImagePickerController *)pickers didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
	selectedImage = [image retain];
	[picker dismissModalViewControllerAnimated:YES];
	[self performSelector:@selector(showUploadImage) withObject:nil afterDelay:0.5];
}
Thank You iSDK i will try that now.
tobyaherbert is offline   Reply With Quote
Old 02-20-2011, 10:49 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Paris, France
Posts: 946
7twenty7 is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
I think the better thing to do is set the imageview's image from the method, dismiss the imagepicker, and then perform a void method after 0.5 seconds of the pickerview dismissing which would present the mailcomposer.
I don't think that's the problem. Looks like you're using the actual string "UIImagePickerControllerOriginalImage" rather than the defined variable. That is, you want to do:

Code:
// notice the lack of quotes
theimageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
Two more things--

Definitely use the callback in your original post--not the one from iSDK. The imagePickerController:didFinishPickingImage:editin gInfo callback was deprecated in iOS 3.0.

Also, relying on specific timings to perform functions (like the call a void method 0.5 seconds after...etc), is destined to fail at some point. You can't rely on specific times on different devices, OS versions, and whatever else might be happening on the device at a particular time. Use the various UIViewController methods to notify you that an even finished (eg, viewDidAppear, etc).
7twenty7 is offline   Reply With Quote
Reply

Bookmarks

Tags
image, mail, mfmailcomposer, photo, picture

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 379
14 members and 365 guests
cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, mottdog, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0