在 .h 文件中添加 MFMailComposeViewControllerDelegate
@interface VideoPlayAndSharing : UIViewController
<MFMailComposeViewControllerDelegate>
显示作曲表
-(void)displayComposerSheet
{
if ((videodta.length/1024)/1024 < 25)
{
NSLog(@"Video size >> %d",videodta.length/1024);
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Your subject"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"rajneesh071@gmail.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
[picker addAttachmentData:videodta mimeType:@"video/mp4" fileName:@"MyPersonalMessage"];
// Fill out the email body text
NSString *emailBody = @"Type your message here";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Personal Message"
message:@"Video exceed the limit of 25 MB"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
}
和委托方法
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
message.text = @"Result: canceled";
break;
case MFMailComposeResultSaved:
message.text = @"Result: saved";
break;
case MFMailComposeResultSent:
message.text = @"Result: sent";
break;
case MFMailComposeResultFailed:
message.text = @"Result: failed";
break;
default:
message.text = @"Result: not sent";
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
编辑
picker.mailComposeDelegate
它的代表MFMailComposeViewControllerDelegate
它的回应- (void)mailComposeController
picker.delegate
它的代表UINavigationControllerDelegate
它不响应导航控制器- (void)mailComposeController
,所以取消点击它不会调用,这就是你的MFMailComposeViewController
视图没有隐藏的原因。