4

I have an application which is using standard SMS functionality provided by MFMessageComposeViewController. I have an array of recipients visible in TO: field of the SMS dialog. The user has a possibility to remove or add new recipients. This is ok but my application need to know when the user edit this TO: field, because I have to do some other actions when the receivers field is changed by the user. Is there any way to know if the recipients field are edited or no, after Cancel button click or Send button click?

I have method callback in my code:

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

This method has controller.recipients but this array contains the recipients before calling of the message controller view.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
Petko Yanakiev
  • 159
  • 2
  • 8

2 Answers2

0

This is not possible as of iOS 7. The only information provided by the delegate method is whether the user chose to cancel the message, send the message, or the sending is failed.

From the documentation:

This method is called when the user taps one of the buttons to dismiss the message composition interface. Your implementation of this method should dismiss the view controller and perform any additional actions needed to process the sending of the message. The result parameter lets you know whether the user chose to cancel or send the message or whether sending the message failed.

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
  • I agree with your reading of the docs, but this did confuse me as well. *Here's why* The docs say: `var recipients: [String]? { get set }` Why would you allow `get` of the value unless it reflected *the actual recipients of the message in this VC?` If you just wanted to know what they used for `recipients`, you could easily put that in a variable for later reference. There is no need to `get` whatever you had already passed in. – benc Jun 09 '19 at 07:41
0

To add to Enrico's answer, not only is this not possible from public API standpoint, it is also not possible by trickery, as since iOS6, the mail and message compose view controllers are rendered by different processes than your own, and their view hierarchies are completely hidden to your application. Indeed, if you were to inspect the view hierarchy of the message compose view controller's view, you would notice that none of what is on screen is actually there in the hierarchy. During the remote view's loading, the settings given to the message compose view controller are passed to the remote view controller. However, this is a one-way operation, and the properties are not updated (or read from) after the remote view is loaded.

This is to protect the user's privacy. This is a fundamental design of iOS. You should accept this, and design your application accordingly.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195