Crash On MFMailComposeViewController For iPad

穿精又带淫゛_ 提交于 2019-12-11 09:22:54

问题


- (void) mailshareClick:(UIButton *)sender
{
    NSString  *_message = @"wait for set up Mail";
    [self waitForWhile:_message];
    if ([MFMailComposeViewController canSendMail]){
        [NSThread detachNewThreadSelector:@selector(mailFunction) toTarget:self withObject:nil];
    }
    else {
        _message = @"Please set Mail account";
        [self remove:_message];
    }
}
- (void) mailFunction
{
    NSData *data = nil;
    if ([self.files.imageArr count]>0) 
    {
        XXImage *single = [self.files.imageArr objectAtIndex:0];
        UIImage *image = [[SDImageCache sharedImageCache] imageFromKey:[[single.imagearray objectAtIndex:0] columnImage]];
        data = [UIImageJPEGRepresentation(image, 1.0f) retain];
    }
    [self performSelectorOnMainThread:@selector(mailFinished:) withObject:data waitUntilDone:YES];    
    [data release];
}
- (void) mailFinished:(NSData *)_data
{
    if ([MFMailComposeViewController canSendMail]){
        NSData *data = [_data retain];
        MFMailComposeViewController   *message = [[MFMailComposeViewController alloc] init];
        //Title
        [message setSubject:self.files.title];
        //Body
        [message setMessageBody:@"111" isHTML:YES];

        [message setToRecipients:[NSArray arrayWithObject:@"mail"]];
        //Content
        if (data != nil) {
            NSString *picStr = [[NSString alloc] initWithFormat:@"%@%@",OutsideWebsite_Normal,self.files.middlePicPath];
            [message addAttachmentData: data mimeType: @"" fileName:picStr];
            [picStr release];
            [data release];
        }
        message.mailComposeDelegate = self;
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            message.modalPresentationStyle = UIModalPresentationFormSheet;
        }
        [self presentModalViewController:message animated:YES];

        [self remove:@"Set up Ok"];
        [message release];
    }
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result) {
        case MFMailComposeResultSent:
        {
            NSLog(@"MFMailComposeResultSent");
            break;
        }
        case MFMailComposeResultSaved:
        {
            NSLog(@"MFMailComposeResultSaved");
            break;
        }
        case MFMailComposeResultFailed:
        {
            NSLog(@"MFMailComposeResultFailed");
            break;
        }
        case MFMailComposeResultCancelled:
        {
            NSLog(@"MFMailComposeResultCancelled");
            break;
        }
        default:
            break;
    }
    [self performSelector:@selector(delayDismissModalView) withObject:nil afterDelay:1];
}
-(void)delayDismissModalView
{
    [self dismissModalViewControllerAnimated:YES];
}

After invoke a few times the email method , there will be

  • [MFSearchResultsViewController hash]: message sent to deallocated instance Or

  • [MFMailComposeViewController hash]: message sent to deallocated instance

crash.

As you think of that, what is the MFSearchResultsViewController function.

Whether it can solve the problem,please give me a hand.


回答1:


You have to setDelegate for the mail controller. If you set the delegate to "self", make sure that the "self" has <MFMailComposeViewControllerDelegate>. If all these can't make it work, make sure you didn't call presentModalViewController twice.



来源:https://stackoverflow.com/questions/8020214/crash-on-mfmailcomposeviewcontroller-for-ipad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!