[英]MFMailComposeViewController only presented after second tap
我想从模态视图控制器中呈现MFMailComposeViewController
。 基本上,此方法有效,但不能可靠地起作用:
-(void)sendMailTapped:(id)sender{
[self resetButtonsStateAfterTapping:sender];
[self dismissPopover];
if (filesize>10) {
[self showAlertForExceededMaximumAttachmentSize];
return;
}
@try {
MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail]) {
picker.mailComposeDelegate = self;
NSURL *path =[NSURL urlWithPath:[pageInfoDict valueForKey:@"file_name"]
docId:[pageInfoDict valueForKey:@"id_doc"]
encrypted:[[pageInfoDict valueForKey:@"encrypted"]
boolValue]] ;
NSString *fileName = [pageInfoDict valueForKey:@"title"];
if([fileName length] == 0) {
fileName = [path lastPathComponent];
}
if(![fileName hasSuffix:[path pathExtension]]){
fileName=[fileName stringByAppendingFormat:@".%@",[path pathExtension]];
}
[picker setSubject:[@"Send document: " stringByAppendingString:fileName]];
NSArray *ccRecipients = [NSArray arrayWithObjects:
[[CustomisationConfig getAppConfig] getCCMail],nil];
[picker setCcRecipients:ccRecipients];
NSArray *bccRecipients = [NSArray arrayWithObjects:
[[CustomisationConfig getAppConfig] getBCCMail],nil];
[picker setBccRecipients:bccRecipients];
NSData *myData = [path decryptedData];
[picker addAttachmentData:myData
mimeType:fileMIMEType(fileName) fileName:fileName];
NSString *emailBody = [NSString stringWithFormat:
@"\n\nThis file was sent using %@.",
[DCConfiguration getHumanReadableAppName] ];
[picker setMessageBody:emailBody isHTML:NO];
[self presentViewController:picker animated:true completion:^(void){}];
}
}
@catch (NSException *exception) {
NSLog(@"ContextMenuViewController sendMailTapped:%@",exception.description);
}
}
如果我重新启动iPad并打开应用程序,则仅在第二次点击相应按钮时才会显示选择器。
如果我在此之后再次单击该按钮,则选择器每次都会在第一次触摸时显示,并且效果很好,直到我关闭并重新启动iPad。
将以下内容打印到控制台:
Warning: Attempt to present <MFMailComposeViewController: 0x200cbb70> on <ContextMenuViewController: 0x200cd1a0> whose view is not in the window hierarchy!
什么叫sendMailTapped:
方法? 如果是其接口构建器,则需要将其更改为IBAction
而不是void
,并将它们连接到接口构建器中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.