2

如何在 ios6 中将图像附加到本机消息编辑器?我想通过我们可以在默认照片应用程序中看到的消息功能实现相同的共享。

谢谢

4

3 回答 3

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];

长按并单击粘贴,消息将被粘贴...

希望这会有所帮助...图片指的是您传递的 UIImage...

于 2013-05-28T06:01:08.540 回答
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];

}
于 2013-05-28T06:15:39.883 回答
0

我认为您不能在消息编辑器中附加图像。只有在邮件作曲家中才有可能。

于 2013-05-28T06:42:02.050 回答