【问题标题】:iPhone:send image+text to iMessage from my own appiPhone:从我自己的应用程序将图像+文本发送到 iMessage
【发布时间】:2011-12-09 12:01:28
【问题描述】:

我想从我自己在 ios5 中的应用程序向 iMessage 发送图像和文本。

是否可以从应用程序向 iMessage 发送图像?

如果是的话

那么它的编码是什么,我应该在我的应用程序中添加哪些框架?

请帮帮我...

【问题讨论】:

    标签: iphone objective-c ios5


    【解决方案1】:

    不,这是不可能的,首先你们需要使用只支持文本的MFMessageComposeViewController

    也没有办法检测消息是否将通过iMessage发送

    【讨论】:

    • 是否可以以编程方式从我的应用程序切换到 iMessage 并从我的应用程序在 iMessage 应用程序中加载一些文本。我想为用户提供通过 MFMessageComposeViewController 发送消息的功能,但如果设备不是 iphone,我想为用户提供通过 i Message 发送消息的选项。
    • MFMessageComposeViewController 也适用于 iPod touch 和 iPad。
    • 显然可以在 IMessage 中发送图像,我不知道如何,但很多应用程序都是这样做的(例如 whatsapp 和 9gag)
    • 是的,现在是,但在 2011 年不是。您现在可以使用MFMessageComposeViewController 发送附件。
    【解决方案2】:

    这是我将 .mp4 作为邮件附件发送的操作

    在您的 .h 文件中 #进口 和 MFMessageComposeViewControllerDelegate>

    .m 文件中的方法

    -(void)sendMovieWithMessage{
    
    MFMessageComposeViewController* messageComposer = [MFMessageComposeViewController new];
    messageComposer.messageComposeDelegate = self;
    [messageComposer setBody:@""];
    
    NSData *attachment = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:[self bringFilePathfromDocumentsDirectory:@"your file.mp4"]] options:NSDataReadingUncached error:nil];
    [messageComposer addAttachmentData:attachment typeIdentifier:@"video/mp4" filename:@"your file.mp4"];
    
    
    
    [self presentViewController:messageComposer animated:YES completion:nil];
    
    
    }
    

    //委托

    - (void)messageComposeViewController:(MFMessageComposeViewController     *)controller didFinishWithResult:(MessageComposeResult)result{
    
    [self dismissViewControllerAnimated:YES completion:^{
    
    
    }];
    
     }
    

    【讨论】:

      【解决方案3】:

      虽然这是一个老问题,但我只是想添加这个来帮助在谷歌上找到这个的人:

      要使以下代码正常工作,您必须导入:

      #import <MessageUI/MessageUI.h>
      

      并在您的构建设置中链接MessageUI.framework (Project Name &gt; Build Phases &gt; Link Binary with Libraries)

      我的以下代码适用于视频和图像,因此您必须将其设置为任一:

      NSString *attachmentType = @"image";NSString *attachmentType = @"video";

      你还必须设置attachment NSData:

      NSData *attachment = UIImageJPEGRepresentation(YOUR_IMAGE,.5)
      

      这是设置图像的示例。 .5 是图像质量,我发现它是质量和尺寸之间的良好折衷。 1.0 是最好的质量(和最大的尺寸!)

      MFMessageComposeViewController* messageComposer = [MFMessageComposeViewController new];
          messageComposer.messageComposeDelegate = self;
          [messageComposer setBody:message];
          [messageComposer setRecipients:recipients];colorForUsage:SC_THEME_MAIN];
          if (attachment && attachmentType) {
              if ([attachmentType isEqual:@"image"]) {
                  [messageComposer addAttachmentData:attachment typeIdentifier:@"image/jpeg" filename:@"shotnote.jpg"];
              }
              if ([attachmentType isEqual:@"video"]) {
                  [messageComposer addAttachmentData:attachment typeIdentifier:@"video/mp4" filename:@"shotnote.mp4"];
              }
          }
      [YOUR_CURRENT_VIEW_CONTROLLER 
           presentViewController:messageComposer
           animated:YES
           completion:nil];
      

      还要确保实现MFMessageComposeViewControllerDelegate 协议,以便能够在用户按下发送或取消时真正关闭消息撰写视图控制器!

      - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
      

      干杯!

      【讨论】:

        【解决方案4】:

        您发送它的方式与发送 SMS 的方式相同 - 如果您发送到的帐户启用了 iMessage,那么它将发送到 iMessage。 Apple ios5 iMessage read and write http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMessageComposeViewController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009668

        就在您的应用中检测某人是否有 iMessage 而言...我不确定您是否可以。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-07-22
          • 1970-01-01
          • 1970-01-01
          • 2014-06-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多