Disable editing on MFMailComposeViewController

两盒软妹~` 提交于 2019-12-30 07:26:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!