Tapy Tapy - 1 year ago 84
Objective-C Question

Open Message app (SMS app) with a button and a Text field/View (iPhone)

Would this be possible?

The app will have a button and a Text Field or a Text View.

The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Message or SMS app in the iPhone.

How would I do this? If possible please provide some code! :)

Thank you in advance!

Answer Source

Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.

You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
picker.body = yourTextField.text

[self presentModalViewController:picker animated:YES];
[picker release];

You need to first import the MessageUI.framework (see this answer).

Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate> 
    // ...