【问题标题】:Attach image to message composer in ios 6将图像附加到 ios 6 中的消息编辑器
【发布时间】:2013-05-28 05:59:22
【问题描述】:

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

谢谢

【问题讨论】:

标签: iphone ios objective-c


【解决方案1】:

对于邮件:

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

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

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

【讨论】:

  • 感谢您的回答。什么是“邮件控制器”?是 MFMessageComposer 还是 Email Composer?
  • MFMailComposeViewController *mailController .. 在第一行声明。
  • MFMessageComposeViewController 没有这样的方法 [messageCo addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];
  • @sajaz MFMessageComposeViewController 无法将附件添加到正文。它只接受正文的 NSString。 developer.apple.com/library/ios/documentation/MessageUI/…
  • @verbumdei 感谢您的评论。这意味着我们不能通过 iMessage 从应用程序共享图像?目前只能通过 iphone 的默认照片应用程序实现?
【解决方案2】:
{
  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];

}

【讨论】:

  • 我想通过消息编辑器而不是电子邮件编辑器分享
【解决方案3】:

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

【讨论】:

  • 那我们如何在ios5以上通过iMe​​ssage分享图片呢?
  • 我在这个主题上为我的应用做了很多尝试。但我没有找到任何解决方案。无论如何,您可以继续搜索。我只是表达了我的想法
  • 感谢您的想法,让我们看看
猜你喜欢
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
  • 2021-03-17
  • 1970-01-01
  • 2011-04-21
  • 1970-01-01
相关资源
最近更新 更多