MFMessageComposeViewController not displaying camera icon
Asked Answered
E

2

8

When I bring up a "New Message" manually I will see a camera icon to the left of the text edit area. When I use the MFMessageComposeViewController it will not display this icon which means you cannot insert images. I know this can be done because the guys that made txtAgif can do it. One subtle difference is the Caps is turned on. This might be a clue as to how they are getting this to work.

I know that MFMessageComposeViewController does not allow you to insert images programmatically and that is why I'm doing the copy to UIPasteboard trick. This part works perfectly.

This same question has been asked here and here the question has not been answered except for the "It can't be done."

This is my first post so I did not have a high enough ranking to contribute to the other question posts.

How are they doing this? Is there a trick to MFMessageComposeViewController or are they using something completely different?

Eskisehir answered 19/3, 2012 at 22:21 Comment(0)
A
4

I have fixed this by following code:

 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
           pasteboard.persistent = YES;
           NSString *imagefile =app.strimagepath;

           ///  
           BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];

           if (fileExists)
           {    
               NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
               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];

Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.

Allhallows answered 25/5, 2012 at 11:54 Comment(2)
You only add the copying to the clipboard. The key to the answer to my question is that you have to use UIApplication to launch the message view. Now post an example using MFMessageComposeViewController that works. It isn't unless Apple updates this class.Eskisehir
when you cannot see the camera button or you cannot paste, just try by adding valid Message id of recipient and it will enable the camera icon as well as will let you paste the image.Allhallows
E
3

I found the answer! Using UIApplication sharedApplication to launch a blank message works while MFMessageComposeViewController does not. Because I'm using the UIPasteboard I do not need to insert items into the body.

    NSString *phoneToCall = @"sms: 123-456-7890";
    NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];

    [[UIApplication sharedApplication] openURL:url];

This is a bug in MFMessageComposeViewController because why would they allow images to be inserted into one and not the other. I would insert an image but I'm not allowed to because I do not have enough reputation.

Eskisehir answered 20/3, 2012 at 19:37 Comment(5)
now if your reputation is increased... please insert an imageAstraddle
Do you still need help with this kdeo_16?Eskisehir
no no i try this already and it works... i tried it i think 2 weeks before after waiting for your replyAstraddle
Is there a way to initialize what the message says in a similar fashion as what number to text? That way you can put in a message something along the lines of "paste image here"?Cornelia
@Boeckm: I know exactly what you are talking about. Unfortunately I could only add a message using 'MFMessageComposeViewController'Eskisehir

© 2022 - 2024 — McMap. All rights reserved.