如何使用 MFMailComposeViewController 发送图像
我正在尝试使用 MFMailComposeViewController 发送电子邮件,但不知何故它不起作用。当我不发送图像时,一切正常。但如果我尝试添加照片,则会出现以下错误:
-(IBAction)gonder:(id)sender{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setSubject:@"deneme"];
UIImage *savedImage = self.image;
NSData *imageData = UIImagePNGRepresentation(savedImage);
[mailComposeViewController addAttachmentData:imageData mimeType:@"image/png" fileName:@"photo"];
NSString *emailBody = @"my text";
[mailComposeViewController setMessageBody:emailBody isHTML:NO];
[emailBody release];
NSArray *alicilar=[[NSArray alloc]initWithObjects:@"mymailadress.com", nil];
[mailComposeViewController setToRecipients:alicilar];
[mailComposeViewController view];
}
- (void) mailComposeController:(MFMailComposeViewController*)mailComposeViewController bodyFinishedLoadingWithResult:(NSInteger)result error:(NSError*)error
{
@try
{
id mailComposeController = [mailComposeViewController valueForKeyPath:@"internal.mailComposeController"];
id sendButtonItem = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.sendButtonItem"];
[mailComposeController performSelector:@selector(send:) withObject:sendButtonItem];
}
@catch (NSException *e) {}
[mailComposeViewController release];
}
这些是错误:2012-02-14 16:19:58.322 il[653:307] *** 错误:FigCreateCGImageFromJPEG 返回 -12905。输入(空)为 444585 字节。
I am trying to send an email using MFMailComposeViewController but somehow it won't work. When I don't send an image everything works just fine. But if I try to add photo there is the following error:
-(IBAction)gonder:(id)sender{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setSubject:@"deneme"];
UIImage *savedImage = self.image;
NSData *imageData = UIImagePNGRepresentation(savedImage);
[mailComposeViewController addAttachmentData:imageData mimeType:@"image/png" fileName:@"photo"];
NSString *emailBody = @"my text";
[mailComposeViewController setMessageBody:emailBody isHTML:NO];
[emailBody release];
NSArray *alicilar=[[NSArray alloc]initWithObjects:@"mymailadress.com", nil];
[mailComposeViewController setToRecipients:alicilar];
[mailComposeViewController view];
}
- (void) mailComposeController:(MFMailComposeViewController*)mailComposeViewController bodyFinishedLoadingWithResult:(NSInteger)result error:(NSError*)error
{
@try
{
id mailComposeController = [mailComposeViewController valueForKeyPath:@"internal.mailComposeController"];
id sendButtonItem = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.sendButtonItem"];
[mailComposeController performSelector:@selector(send:) withObject:sendButtonItem];
}
@catch (NSException *e) {}
[mailComposeViewController release];
}
Those are the errors:2012-02-14 16:19:58.322 il[653:307] *** ERROR: FigCreateCGImageFromJPEG returned -12905. Input (null) was 444585 bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试附加的图像非常大吗?这可能是内存不足的问题。
Is the image you are trying to attach very large? It may be an out of memory problem.
我认为问题在于创建数据对象的方式。试试这个:
也可以考虑使用 JPEG 而不是 PNG,它的速度要快得多。
i think the issue is the way you create the data object. try this:
also consider maybe using JPEG instead of PNG, it's quite a bit faster.