我正在打开一封电子邮件表来发送文件。除了我不能回到我的应用程序之外,它的效果很好。
当我点击取消按钮时,会询问是删除还是保存草稿,并保留在那里。它不会返回应用页面。
代码:
//send email log-------------------------
NSLog(@"mail");
[[CCDirector sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
//Fill in the email as you see fit
NSArray *toRecipients = [NSArray arrayWithObject:@"name@gmail.com"];
[picker setToRecipients:toRecipients];
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths2 objectAtIndex:0] stringByAppendingPathComponent:@"Test.txt"];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[picker addAttachmentData:data mimeType:@"text/txt" fileName:@"Test.txt"];
NSString *emailBody = @"Test ";
[picker setMessageBody:emailBody isHTML:NO];
[picker setSubject:@"hardware test ## "];
//display the view
[[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
[[CCDirector sharedDirector] stopAnimation];
修改
我已经在这里添加了答案中建议的功能,当我点击取消时他调用了该功能,但它保留在该表中。 我不得不说我正在使用cclayer(cocos2d),因此该层定义为:
@interface HelloWorldLayer : CCLayer< MFMailComposeViewControllerDelegate>
还有其他建议吗?
非常感谢。
答案 0 :(得分:4)
您必须实现委托方法
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
并关闭那里的视图控制器:
[picker dismissViewControllerAnimated:YES completion:^{}];
更新:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[picker dismissViewControllerAnimated:YES completion:^{}];
}