简体   繁体   English

MFMailComposeViewController仅在第二次点击后出现

[英]MFMailComposeViewController only presented after second tap

I want to present a MFMailComposeViewController from a modal view controller. 我想从模态视图控制器中呈现MFMailComposeViewController Basically this method works, but it does not work reliably: 基本上,此方法有效,但不能可靠地起作用:

-(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);
    }      
}

If I restart my iPad and open the app, the picker will be presented only on the second tap on the corresponding button. 如果我重新启动iPad并打开应用程序,则仅在第二次点击相应按钮时才会显示选择器。
If I click again on the button after this, the picker will be presented on first touch everytime and it works perfectly, until I shutdown and restart the iPad. 如果我在此之后再次单击该按钮,则选择器每次都会在第一次触摸时显示,并且效果很好,直到我关闭并重新启动iPad。

The following is printed to the console: 将以下内容打印到控制台:

Warning: Attempt to present <MFMailComposeViewController: 0x200cbb70> on <ContextMenuViewController: 0x200cd1a0> whose view is not in the window hierarchy!

What is calling the sendMailTapped: method? 什么叫sendMailTapped:方法? If its interface builder, you need to change it to IBAction instead of void , and connect them in interface builder. 如果是其接口构建器,则需要将其更改为IBAction而不是void ,并将它们连接到接口构建器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 弹跳 animation 仅在第二次点击后才工作 [SwiftUI] - Bounce animation is working only after second tap [SwiftUI] ViewController 仅在用户触摸屏幕后呈现 - ViewController Only Presented after User Touches the Screen 将MFMailComposeViewController推入导航堆栈? 没有模态呈现 - Pushing an MFMailComposeViewController onto the navigation stack? Not presented modally MFMailComposeViewController出现一秒钟然后消失 - MFMailComposeViewController appears for a second then disappears 添加新注释后,我的第一次点击没有处理,但第二次点击是 - After adding a new annotation, my first tap is not handled, but the second tap is 第二次点击后有时会调用UITableView didSelectRowAtIndexPath - UITableView didSelectRowAtIndexPath sometimes called after second tap 仅在MFMailComposeViewController中设置的主题 - Only subject set in MFMailComposeViewController 快速布局的自动布局约束仅在点击后才应用 - Autolayout constraint with swift only applied after tap Swift UICollectionView 工作奇怪,只记录第二次点击 - Swift UICollectionView works strange, registers only second tap 验证后无法直接登录,但第二次点击成功 - Failure to login straight after verifying but successful on second tap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM