.hファイルに追加していますか MFMailComposeViewControllerDelegate
@interface VideoPlayAndSharing : UIViewController
<MFMailComposeViewControllerDelegate>
ComposerSheet の表示
-(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
ビューが非表示になりません。