iOSシミュレーターでメール作成者を表示するだけです(実際のメールを送信する必要はありません)。
を初期化するとすぐに MFMailComposeViewController
電子メールアカウントが設定されていないという警告ポップアップが表示されます。
これは私がやっていることです。
MFMailComposeViewController* composeVC = [[MFMailComposeViewController alloc] init];
この行は、アラートコントローラーをポップアップします。
回答:
回答№1は1シミュレーターの場合、電子メール構成は使用できません。
以下のコードを使用してメールを送信します。
- (void)openEmail
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mail =
[[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:@"Subject"];
[mail setMessageBody:@"body message" isHTML:NO];
[mail setToRecipients:@[@"email1@example.com",@"email2@example.com"]];
/// if attachment then implement below line
//[mail addAttachmentData:<#(nonnull NSData *)#> mimeType:<#(nonnull NSString *)#> fileName:<#(nonnull NSString *)#>]
[self presentViewController:mail animated:YES completion:NULL];
}
else {
NSLog(@"Please configure your email. Settings->Accounts & Passwords->Add Account");
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error
{
switch (result) {
case MFMailComposeResultSent:
NSLog(@"Sent");
break;
default:
break;
}
}