Xcode:将MKmapView的屏幕截图发送到电子邮件附件

时间:2011-08-06 15:54:38

标签: xcode4 mkmapview screenshot email-attachments

我正在使用Xcode 4 Beta在地图上显示用户位置,工作正常。 接下来我拍摄地图的屏幕截图并将其显示为电子邮件中的附件(下面的代码将地图屏幕截图附加到电子邮件中,但发送的图像仅为灰色网格线)

你能帮忙吗,这是谷歌的限制吗?还是有另一种方法可以做到这一点

p.s我尝试手动截取地图的截图,它可以在我的iphone 4上运行。

- (IBAction)buttonPress:(id)sender {

UIGraphicsBeginImageContext(mapView.frame.size);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData * imageData = UIImageJPEGRepresentation(image,2.0);


if 
   ( [MFMailComposeViewController canSendMail] ) {
   MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.delegate = self;
   [mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"attachment.jpng"];

    /* Configure other settings */
        [mailComposer setSubject:@"subject here"];
       [mailComposer setToRecipients:[NSArray arrayWithObjects:@"123@abc.com", nil]];


    [self presentModalViewController:mailComposer animated:YES];
           }

}


我已经玩过代码最终使它工作,但我面临的另一个问题是电子邮件拒绝发送,并放在我的电子邮件中的未发送消息框中。 hotmail帐户向我显示一条错误消息,指出“已将副本放入发件箱。将消息内容发送到服务器失败”

你能帮忙吗

这可能是因为使用谷歌地图复制正确的问题吗?或者是代码错误

1 个答案:

答案 0 :(得分:1)

据我所知,您应该使用NUIImagePNGRepresentation()代替UIImageJPEGRepresentation(image,2.0);,因为屏幕截图是PNG的。

除此之外,我不知道你的代码有什么问题。