如何将图像附加到ios6中的本机消息编写器?我想通过默认照片应用程序中可以看到的消息功能实现相同的共享。
谢谢
答案 0 :(得分:4)
邮件:
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
NSData *exportData = UIImageJPEGRepresentation(pic ,1.0);
[mailController addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];
[self presentModalViewController:mailController animated:YES];
唯一的方法是通过电子邮件当前。除非你想创建一个自己的MMS网关,以允许你的应用程序支持MMS ..
对于消息:
在阅读之后,您可以使用UIApplication sharedApplication而不是使用MFMessageComposeViewController。
示例:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSData *data = UIImageJPEGRepresentation(pic ,1.0);
pasteboard.image = [UIImage imageWithData:data];
NSString *phoneToCall = @"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Longpress并点击粘贴,邮件将被粘贴...
希望这有帮助... pic指的是你正在经过的UIImage ......
答案 1 :(得分:1)
{
NSMutableDictionary * attachment = [[NSMutableDictionary alloc]init];
[attachment setObject: UIImageJPEGRepresentation(imageView.image,0.5) forKey:@"attachmentData"];
[attachment setObject: @"productImage.jpeg" forKey:@"attachmentFileName"];
[attachment setObject: @"jpeg" forKey:@"attachmentFileMimeType"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject: @"subject" forKey:@"subject"];
[params setObject: @"matterText" forKey:@"matterText"];
[params setObject: [[NSMutableArray alloc]initWithObjects:attachment, nil] forKey:@"attachments"];
}
#pragma mark - Sharing Via Email Related Methods
-(void)emailInfo:(NSMutableDictionary*)info
{
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Email Configuration"
message:@"We cannot send an email right now because your device's email account is not configured. Please configure an email account from your device's Settings, and try again."
delegate:nil
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
return;
}
MFMailComposeViewController *emailer = [[MFMailComposeViewController alloc] init];
emailer.mailComposeDelegate = self;
NSString * subject = [info objectForKey:@"subject"];
NSString * matterText = [info objectForKey:@"matterText"];
if(subject)
[emailer setSubject:subject];
if(matterText)
[emailer setMessageBody:matterText isHTML:NO];
NSMutableArray * attachments = [info objectForKey:@"attachments"];
if (attachments)
{
for (int i = 0 ; i < attachments.count ; i++)
{
NSMutableDictionary * attachment = [attachments objectAtIndex:i];
NSData * attachmentData = [attachment objectForKey:@"attachmentData"];
NSString * attachmentFileName = [attachment objectForKey:@"attachmentFileName"];
NSString * attachmentFileMimeType = [attachment objectForKey:@"attachmentFileMimeType"];
[emailer addAttachmentData:attachmentData mimeType:attachmentFileMimeType fileName:attachmentFileName];
}
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
emailer.modalPresentationStyle = UIModalPresentationPageSheet;
}
[self.navigationController.topViewController presentViewController:emailer animated:YES completion:nil];
}
答案 2 :(得分:0)
我认为您无法在消息编写器中附加图像。它只能在邮件编辑器中使用。