我想发送一封电子邮件,但是当我点击发送时,它确实会发送该电子邮件,但视图未关闭。
MainViewController.m
NSString *text = [self fetchLogCoreData];
PlistCreatorViewController *plistCreator = [[PlistCreatorViewController alloc] init];
[plistCreator sendPlist2Email:self text:text];
我在coreData中获取所有数据,然后将其放入NSString中。 然后使用self作为视图调用sendPlist2Email,将文本调用为我想在电子邮件中使用的文本。
PlistCreatorViewController.m
-(void)sendPlist2Email: (UIViewController*) viewController text:(NSString*)text{
NSString *emailTitle = @"PickDPack App: DATA";
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:text isHTML:NO];
// Determine the file name and extension
// Get the resource path and read the file using NSData
// Add attachment
[viewController presentViewController:mc animated:YES completion:nil];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
MainViewController *mainView = [[MainViewController alloc] init];
// Close the Mail Interface
NSLog(@"Email_out");
[mainView dismissViewControllerAnimated:YES completion:NULL];
}
非常简单,即时发送电子邮件,但按下发送/取消时窗口不会关闭。
我已尝试将self
置于[mainView dismissViewControllerAnimated:YES completion:NULL];
更改mainView
,但没有任何变化。
我已将此代码放在MainViewController.m
中,但没有任何变化。
我希望有人能帮助我:S
THX
答案 0 :(得分:0)
您是否尝试过如下?
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[controller dismissViewControllerAnimated:YES completion:NULL];
}