Issues with including an email application in my application

When a button is pressed, is displayed MFMailComposeViewController.

So far I have done it.

My question is:

  • Can I turn off the pop-up action window when I click the cancel button?
  • Is it possible to make non-editable fields subject and subject?
  • I want to change the left bar button back.

How can i do this?

- (IBAction)questionButtonPressed:(id)sender {
    email = [[MFMailComposeViewController alloc] init];
    email.mailComposeDelegate = self;

    // Subject
    [email setSubject:@"Testing"];

    // Optional Attachments
    NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:@"albumart.png"]);
    [email addAttachmentData:artwork mimeType:@"image/png" fileName:@"albumart.png"];

    // Body
    //[email setMessageBody:@"This is the body"];

    // Present it
    [self presentModalViewController:email animated:YES];
}
+3
source share
2 answers

Yes. All three are possible, but No. 2 will require the use of a private API or hacker. I took the subclass approach of MFMailComposeViewController as below

// file: CustomMailComposeViewController.h
@interface CustomMailComposeViewController : MFMailComposeViewController {

}
@end

// file ustomMailComposeViewController.m
#import "CustomMailComposeViewController.h"
@implementation CustomMailComposeViewController

-(void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];

  //Here we replace the cancel button with a back button (Question #3)
  UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)];
  self.navigationBar.topItem.leftBarButtonItem  = backButton;
  [backButton release];


  //Here we disallow the user to change to to: cc: bcc: and subject: feilds (Question #2)
  //Warning: the xxxField methods are undocumented private methods. 
  UITableViewController *vc = [self.viewControllers objectAtIndex:0];
  UITableView *tvv = [vc view];
  [[tvv toField] setUserInteractionEnabled:NO];
  [[tvv ccField] setUserInteractionEnabled:NO];
  [[tvv bccField] setUserInteractionEnabled:NO];
  [[tvv multiField] setUserInteractionEnabled:NO];
  [[tvv subjectField] setUserInteractionEnabled:NO];
}


//This is the target for the back button, to immeditally dismiss the VC without an action sheet (#1)
-(void) backButtonPressed:(id)sender {
  [self dismissModalViewControllerAnimated:YES]; 
}
@end

To use in your code, you would have to change: [[MFMailComposeViewController alloc] init]; in [[CustomMailComposeViewController alloc] init];

+3

!

0

Source: https://habr.com/ru/post/1785369/


All Articles