We have a business rule where we need to restrict the editing of the email body content on MFMailComposeViewController. The content will be pre-populated and needs to remain static. Is it possible to grab the UITextView object and set it to disabled or something along those lines?
Another thought was to display a clear view over the top of the UITextView to prevent any interaction.
Any ideas?
Ok, so yes, the answer is that it is impossible without using private APIs.
I managed to do it with the following code.
- (void) getMFComposeBodyFieldViewFromView:(UIView *)view {
for (UIView *item in view.subviews) {
if ([[[item class] description] isEqualToString:@"MFComposeTextContentView"]) {
self.mailBodyView = item;
break;
}
if([item.subviews count] > 0) {
[self getMFComposeBodyFieldViewFromView:item];
}
}
}
Then call the above method so that it sets the ivar mailBodyView
and then call the _setEditable:
method on UIWebDocumentView
which MFComposeBodyField
inherits from.
[self getMFComposeBodyFieldViewFromView:mailComposeViewController.view];
[self.mailBodyView setEditable:NO];
This causes the content in the body to be uneditable, the interaction is kind of funky because the keyboard still appears and you can still move the cursor around and select things but it definitely prevents the user from editing.
UPDATE
I updated the code to look for MFComposeTextContentView
which is the parent of MFComposeBodyField
and I call setEditable:
on that object which prevents the keyboard from coming up, much better solution!