问题
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?
回答1:
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!
回答2:
Sorry this is impossible, and violates the Human Interface Guidelines, meaning your application could be denied for doing this. My only advice to you is to create a custom email view controller and implement this instead of using the Apple provided one.
回答3:
This is impossible with the MFMailComposeViewController. If you want to send an email where all of the content is predefined, then you'll just want to do the SMTP connection and send the email yourself using your in house corporate mail server.
回答4:
If the email does not have to originate from the account of the user of the device then you could simply send the email through your own server not using the MFMailComposerViewController. You could also just have your app talk to a web service if this is the case.
来源:https://stackoverflow.com/questions/4786999/disable-editing-on-mfmailcomposeviewcontroller