私のアプリではMFMailComposerを使用しています。メール設定なしでメールを送信すると(メールアプリにメールIDとパスワードを入力しなくても)クラッシュします。MFMailComposerがクラッシュする
[self presentModalViewController:picker animated:YES];
私のアプリではMFMailComposerを使用しています。メール設定なしでメールを送信すると(メールアプリにメールIDとパスワードを入力しなくても)クラッシュします。MFMailComposerがクラッシュする
[self presentModalViewController:picker animated:YES];
-(void) showEmailModalView
{
NSLog(@"Start method <ExportStatisticsController> : <showEmailModalView> --");
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the
//user did with your email sheet
[picker setSubject:SendEmailSubject];
NSArray *torec=[[NSArray alloc] initWithObjects:SendEmailToEmailID, nil];
[picker setToRecipients:torec];
[torec release];
//------ message body ---
NSString *body [email protected]"";
body=[NSString stringWithFormat:@"%@ From : %@\n",body, emailTextField.text];
body=[NSString stringWithFormat:@"%@ Subject : %@\n",body,subjectTextField.text];
//email contents
body = [NSString stringWithFormat:@"%@ Message : \n %@", body,messageBodyTextView.text];
[picker setMessageBody:body isHTML:NO]; // depends. Mostly YES, unless you want to send it as plain text (boring)
picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
[self presentModalViewController:picker animated:YES];
[picker release];
NSLog(@"End method <ExportStatisticsController> : <showEmailModalView> --");
}
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSLog(@"Start method <ExportStatisticsController> : <didFinishWithResult> --");
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Message MFMailComposeResultCancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Message MFMailComposeResultSaved");
break;
case MFMailComposeResultSent:
NSLog(@"Message sent Successfuly");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Mail Sent Successfully!"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
break;
case MFMailComposeResultFailed:
NSLog(@"Message MFMailComposeResultFailed");
break;
default:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed - Unknown Error :-("
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
break;
}
[self dismissModalViewControllerAnimated:YES];
NSLog(@"End method <ExportStatisticsController> : <didFinishWithResult> --");
}
あなたは、ビューコントローラを提示する前に
[MFMailComposeViewController canSendMail]
を呼び出す必要があり、例えば本当だ
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[self presentModalViewController:composer];
} else {
// Show error message maybe
}
:
この
は、クラッシュの原因となるラインです。あなたのメールアプリケーションを設定し、そのデバイスがメールを送信できるかどうかをチェックする必要があります。メールアプリケーションなしで可能だったら、シミュレータを使ってメールを送ることができます(これは不可能と思います)。あなたのメールの受信者は、メールを受け取っている場所から知っていなければなりません。私は間違っている可能性があるコードから送信者を設定することはできないと思いますが、私は同じ状況に苦しんでいたので、希望します。
さらにコードを投稿してください... – mayuur