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];
}