views:

38

answers:

2

I have a simple Application for the iPhone which has a button and uses MFMessageComposeViewControler to send a text message. When the user presses the button, the MFMessageComposeViewController pulls up the keyboard and the user is able to send an sms, as expected.

I'd like to be able to manipulate that keyboard. In other words, for example, if the user goes to send the text "how are you" I'd like to be able to, in my program, recognize the phrase "how are you" and change it to "how is life" or change it to whatever. Is this possible?

Thanks!

A: 

EDIT: I should have read your question more thoroughly before answering.

There is no legal way of editing the keyboard in iOS on the iPhone. As per my answer below, you want to be able to "intercept" the textfield/textview used by the MFMessageComposeViewController.

From studying the MFMessageComposeViewController class (and it's delegate) there is no public way to "intercept" the message being input by the user. The best you can do is to start the user off with some text for their message.

If you wanted to achieve this, which maybe possible through sub-classing MFMessageComposeViewController (and finding out what the textfield/view instance variable is), it is quite likely that Apple may not accept your application to the App Store.


Old Answer: If you want to do something like this you need to look at the delegate methods for the UITextField (UITextFieldDelegate). There are number of different approaches you could take.

textField:shouldChangeCharactersInRange:replacementString: - implementing this method will allow you to change characters as it they are entered.

textFieldDidEndEditing: - implementing this will allow you to "intercept" the textfield that has been edited. In turn you can use the textfield that is passed into the method to get the string and manipulate or change words as you wish.

If you are using a UITextView, it also has its own delegate (UITextViewDelegate) with very similar methods you can implement to intercept the text entered by the user.

JonB
I changed my design. I will have a UITextField that will allow the user to enter in text, then I can manipulate the text they enter and then I can specify the body of the sms to be that text. Now, since I am new to iPhone programming, I have a question that maybe you can help me with? I want to have a view that has a UITextField and a button. The user enters the text in the textfield, then press the button to send the sms. How can I make a ViewController that has an MFMessageComposeViewControllerDelegate AND a UITextFieldDelegate? I need both right?
Robert Eisinger
I will answer in another post, it will be easier.
JonB
A: 

To make a view controller a delegate for two other things, you define it like the below in the header file:

@interface AViewController : UIViewController <UITextFieldDelegate, MFMessageComposeViewControllerDelegate> {

    // Variable Definitions for your
    // textfield and uibutton


}

// Method Declarations here.
// You don't need to define the delegate methods,
// Just implement them in your .m file.

@end

Then use the delegate methods I talked about below to intercept the text that has / is being input.

JonB
Thank you so much! This is perfect.
Robert Eisinger