- (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];
}
在调用电子邮件方法几次后,会有
[MFSearchResultsViewController hash]:发送到解除分配实例的消息 或
[MFMailComposeViewController hash]:发送到解除分配实例的消息
的崩溃。
正如您所想,MFSearchResultsViewController函数是什么。
是否可以解决问题,请帮我一把。
答案 0 :(得分:1)
您必须为邮件控制器设置setDelegate。如果将委托设置为“self”,请确保“self”具有<MFMailComposeViewControllerDelegate>
。如果所有这些都无法正常工作,请确保您没有拨打presentModalViewController
两次。