MFMailComposer在发布后立即解散

时间:2013-11-06 22:44:16

标签: ios7 mfmailcomposeviewcontroller mfmailcomposer

我正在尝试在iOS 7模拟器上启动MFMailComposer,一旦它出现,它会立即自我贬低,我在调试器中收到以下错误。

_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The     operation couldn’t be completed. (Cocoa error 4097.)"

这是我的代码

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
        case 0:
            break;
        case 1:{
            if ([MFMailComposeViewController canSendMail]) {
                MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
                mailViewController.mailComposeDelegate = self;
                [mailViewController setSubject:[NSString stringWithFormat:@"%@ Totals Report",_teamStats.relationshipTeam.teamName]];
                [mailViewController setMessageBody:@"\n\n\n\n\nSent From HoopMetrics" isHTML:NO];
                // Attach a doc to the email

                NSData* data =  [_teamStats.relationshipTeam  pdfDataFromString:_teamStats.teamTotalsAsString];
                [mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:@"Totals Report"];
                [self presentViewController:mailViewController animated:YES completion:nil];

            }
            else{
                HMAlertView*alert = [[HMAlertView alloc]initWithTitle:@"No Email" message:@"Please, set up an email account on your device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
            }
        }
            break;
}

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。只需关闭 UINavigationBar UIBarButtonItem 外观自定义或MFMailComposeViewController可能使用的其他元素。

答案 1 :(得分:0)

使用performSelector

可以解决以下问题
- (IBAction)sendEmail:(id)sender {
  [self performSelector:@selector(showEmailComposer) withObject:nil afterDelay:0.0];

}

-(void) showEmailComposer{


  MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];

  //Set recipients...other stuff
  [mailViewController setToRecipients:recipients];
  [mailViewController setSubject:subject];
  [mailViewController setMessageBody:body isHTML:isHTML];


  mailViewController.title = @"Email VC Title";


  mailViewController.mailComposeDelegate = delegate;
  [self presentViewController:mailViewController
                     animated:YES
                   completion:NULL];

}
相关问题