1
我有点奇怪的问题。我正在尝试发送应用内电子邮件。所以,我使用了MFMailComposeViewController。并且我已经实现了MFMailComposeViewControllerDelegate。 当我点击发送按钮,它应该马上被解雇。在调试模式下,它运行良好,但是,在发布模式下,它是非常缓慢,使用户可以点击发送按钮不止一次,邮件将被发送更多比一次。 我一直困惑了五天。 任何人都可以帮助我? 我的代码:MFMailComposeViewController点击后很慢就解散发送按钮
-(void)sendEMail
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
//[self launchMailAppOnDevice];
} else{
[self launchMailAppOnDevice];
}
} else {
[self launchMailAppOnDevice];
}
}
//可以发送邮件的话
-(void)displayComposerSheet
{
//mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
//设置主题
[mailPicker setSubject: kEmailSubject];
// 添加发送者
NSArray *toRecipients = [NSArray arrayWithObject: kToRecipient];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
//NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]", nil];
[mailPicker setToRecipients: toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// 添加图片
// UIImage *addPic = [UIImage imageNamed: @"123.jpg"];
// NSData *imageData = UIImagePNGRepresentation(addPic); // png
// NSData *imageData = UIImageJPEGRepresentation(addPic, 1); // jpeg
// [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"123.jpg"];
NSString *emailBody = kEmailBody;
[mailPicker setMessageBody:emailBody isHTML:YES];
[self presentViewController:mailPicker animated:YES completion:nil];
}
-(void)sendMailBtnCLicked{
[mailPicker dismissViewControllerAnimated:YES completion:nil];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = kToRecipient;
NSString *subject = kEmailSubject;
//@"mailto:[email protected][email protected],[email protected]&subject=my email!";
NSString *body = kEmailBody;
NSString *email = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", recipients, subject,body];
email = [email stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MFMailComposeResultSent) {
[AccountManager sharedManager].isSentMail = YES;
}
[controller dismissViewControllerAnimated:YES completion:nil];
//[self dismissModalViewControllerAnimated:YES];
}