Issues with including Email app inside my app
When a button is pressed, the MFMailComposeViewController
is presented.
That far I have done.
My question is:
- Is it possible to disable the action sheet popping up when the cancel button is pressed?
- Is it possible to make the to and subject fields non-editable?
- I wanna change the left bar button to back.
How can I do these?
- (IBAction)questionButtonPressed:(id)sender {
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:@"Testing"];
// Optional Attachments
NSD开发者_如何转开发ata *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];
}
Yes All Three are possible, however #2 would either require using a private API or some hackery. I took the approach of subclassing 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 change: [[MFMailComposeViewController alloc] init]; to [[CustomMailComposeViewController alloc] init];
quick answer!
- No
- No
- No
Sorry
精彩评论