截屏 发送邮件

图片截屏,并且存入图片库和document目录下。
然后,将图片作为附件以邮件形式发送。
先来张给力的图片——苍老师,哈哈。
e5b18fe5b995e5bfabe785a7-2011-06-11-e4b88ae58d88012411

截屏实现代码:

- (void)screenShoot {
	[actionBtn setHidden:YES];
	UIGraphicsBeginImageContext(CGSizeMake(320, 480));
	[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
	UIImage *screenshoot = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();

	// 写入图片库
	UIImageWriteToSavedPhotosAlbum(screenshoot, nil, nil, nil);

	// 存入Document目录
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pngPath = [documentsDirectory stringByAppendingPathComponent:@"screenShoot.png"];
	NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(screenshoot)];
	[imageData writeToFile:pngPath atomically:YES];
	[actionBtn setHidden:NO];
}

邮件发送代码:

- (void)sendMsg {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pngPath = [documentsDirectory stringByAppendingPathComponent:@"screenShoot.png"];

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
	picker.mailComposeDelegate = self;

	NSString *subject=[NSString stringWithFormat:@"Screenshoot"];
	[picker setSubject:subject];

	NSString *emailBody=@"This is a screenshoot.";

	NSData* data = [NSData dataWithContentsOfFile:pngPath];
	[picker addAttachmentData:data mimeType:@"image/png" fileName:@"ScreenShoot.png"];

	[picker setMessageBody:emailBody isHTML:YES];
	[self presentModalViewController:picker animated:YES];
    [picker release];
}

#pragma mark -
#pragma mark Compose Mail

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error  {
	[self dismissModalViewControllerAnimated:YES];
}

Demo下载


转自:http://pimacun.72pines.com/2011/06/11/%E4%B8%80%E5%A4%A9%E4%B8%80demo%EF%BC%9A%E6%88%AA%E5%B1%8F-%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6/

阅读更多
文章标签: interface email
个人分类: iPhone
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

关闭
关闭
关闭