1

I want to send an image with my text Message. I have used MFMessageComposeViewController. This is the code i have done:

MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
NSArray *recipents = @[[arr_promoterDetaildata valueForKey:@"phone_number"], @"72345524"];

UIImage *img = [UIImage imageNamed:@"ic_dummy_img"];
NSData *imgData = UIImagePNGRepresentation(img);
BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:@"image.png"];

NSString *message = [NSString stringWithFormat:@"Sending SMS"];

[messageController setRecipients:recipents];
[messageController setBody:message];
if (didAttachImage)
{
    // Present message view controller on screen
    [self presentViewController:messageController animated:YES completion:nil];
}
else 
{
    UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                           message:@"Failed to attach image"
                                                          delegate:nil
                                                 cancelButtonTitle:@"OK"
                                                 otherButtonTitles:nil];
    [warningAlert show];
    return;
}

I have tried so many method’s but it is not attaching image in my message screen. Can anyone help?

David
  • 3,285
  • 1
  • 37
  • 54
Niharika
  • 1,188
  • 15
  • 37
  • Niharika Try this : http://stackoverflow.com/questions/3577565/how-to-attach-image-with-message-via-iphone-application – sohil Jan 20 '17 at 09:36
  • You code is a but weird, first you check if you can send an attachment. Then add an audio file. Then you don't check and create a second message composer with an image attachment. Don't you it does not check if you can send it. Do you see the `can send` in your log? – rckoenes Jan 20 '17 at 09:40
  • @rckoenes i have edited my question. it goes into the didAttachImage condition always, but message screen is not attaching any image with it. – Niharika Jan 20 '17 at 09:44
  • are you checking in simulator or device ? – CodeChanger Jan 20 '17 at 10:12

0 Answers0