2

I want to send image and text to iMessage from my own application in ios5.

Is it possible to send image to iMessage from the app?

If yes, then what is the coding of it and which frameworks should I add in my app?

halfer
  • 19,824
  • 17
  • 99
  • 186
iPhone
  • 4,092
  • 3
  • 34
  • 58

4 Answers4

2

Here is what i have done to send .mp4 as attachment on message

in your .h file #import and MFMessageComposeViewControllerDelegate>

and methods in your .m file

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


}

//Delegate

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

[self dismissViewControllerAnimated:YES completion:^{


}];

 }
bpolat
  • 3,879
  • 20
  • 26
2

NO this is not possible, first of you will need to use MFMessageComposeViewController which only supports text.

Also there is no way to detect if the message will be send via iMessage

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • Is it possible to programatically switch from my app to iMessage and load some text in iMessage App from my app. I want to give user a functionality to send message via MFMessageComposeViewController, but if device is not iphone i want to give user an option to send message via i Message. – NaXir Aug 06 '13 at 10:50
  • `MFMessageComposeViewController` will also work on iPod touch and iPad. – rckoenes Aug 06 '13 at 11:17
  • It evidently possible to send image in IMessage, i don't know how but plenty of applications do that ( whatsapp and 9gag for example) – MichaelB Sep 02 '14 at 11:32
  • Yes now it is, but in 2011 it was not. You can now send attachment with `MFMessageComposeViewController`. – rckoenes Sep 02 '14 at 11:49
1

Although this is an old questions, I just wanted to add this to help out the guys that find this on google:

For the below code to work you have to import:

#import <MessageUI/MessageUI.h>

And have the MessageUI.framework linked in your build settings (Project Name > Build Phases > Link Binary with Libraries)

My code below works for video and image, so you have to set it to either one:

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

also you have to set the attachment NSData:

NSData *attachment = UIImageJPEGRepresentation(YOUR_IMAGE,.5)

This was an example of setting an image. The .5 is the image quality and I found that it is a good tradeoff between quality and size. 1.0 is the best quality (and largest size!)

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

Also make sure to implement the MFMessageComposeViewControllerDelegate protocol, to be able to actually close the message compose view controller when the user presses send or cancel!

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

Cheers!

Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40
0

you send it out the same way you would SMS - if the account you send to is iMessage enabled, then it will send out to 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

As far as detecting in your app if someone has iMessage or not... i'm not sure you can.

Community
  • 1
  • 1