[英]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.