通过电子邮件发送图片

#define COOKBOOK_PURPLE_COLOR	[UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]
#define SETIMAGE(X) [(UIImageView *)self.view setImage:X];
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error  
//实现mailComposeController:didFinishWithResult:error:的协议以进行发送成功或者失败后的处理: 
//该委托方法只是退出邮件编辑界面,没有进行更多的操作。
{ 
    switch (result) 
    { 
        case MFMailComposeResultCancelled: 
            NSLog(@"Mail send canceled..."); 
            break; 
        case MFMailComposeResultSaved: 
            NSLog(@"Mail saved..."); 
            break; 
        case MFMailComposeResultSent: 
            NSLog(@"Mail sent..."); 
            break; 
        case MFMailComposeResultFailed: 
            NSLog(@"Mail send errored: %@...", [error localizedDescription]); 
            break; 
        default: 
            break; 
    } 
	[self dismissModalViewControllerAnimated:YES]; //关闭显示电子邮件内容的那个界面
}

//负责解除控制器的单个回调  在呈现撰写控制器之前 一定要为图像拾取器提供足够的时间完成关闭操作
- (void) dismissHUD  
{
	if (![ModalHUD dismiss])
    {
		[self performSelector:@selector(dismissHUD) withObject:nil afterDelay:0.2f];
    }  //有图片的那个界面
}

ModalHUD中的 dissmiss函数

+ (BOOL) dismiss
{
	UIAlertView *av;
	
	if (av = (UIAlertView *)[[[UIApplication sharedApplication] keyWindow] viewWithTag:MODAL_HUD_UNIQUE_ID])
	{
		[av dismissWithClickedButtonIndex:0 animated:YES];  //取消显示alertView。代码和显示效果都非常优雅
		return YES;
	}
	
	return NO;
}
- (void) emailImage: (UIImage *) image
{
    //MFMailComposeViewController以实现了在当 前应用内编辑和发送邮件。
    
	if ([MFMailComposeViewController canSendMail])
	{
		MFMailComposeViewController *mcvc = [[[MFMailComposeViewController alloc] init] autorelease];
		mcvc.mailComposeDelegate = self;
		[mcvc setSubject:@"Here's a great photo!"];  //设置了初始文本电子邮件的主题行。
		NSString *body = @"<h1>Check this out</h1><p>I selected this image from the <code><b>UIImagePickerController</b></code>.</p>";
		[mcvc setMessageBody:body isHTML:YES];
		[mcvc addAttachmentData:UIImageJPEGRepresentation(image, 1.0f) 
                       mimeType:@"image/jpeg" 
                       fileName:@"pickerimage.jpg"];
		[self presentModalViewController:mcvc animated:YES]; //显示一个半透明窗口
		[self dismissHUD];  //如果删掉 有滑轮的那个窗口不会消失
	}
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
	[ModalHUD showHUD:@"Preparing message.\nPlease wait."];
	UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
	[self dismissModalViewControllerAnimated:YES];
	[self performSelector:@selector(emailImage:) withObject:image afterDelay:0.8f];
	[picker release];
}



你可能感兴趣的:(image,action)