メール機能を数回使用していることに気付いたので、コードを数回コピーして貼り付けるのではなく、数回繰り返される関数用に独立したクラスを作成することにしました
クラスは正常に呼び出され、電子メール機能も正常に呼び出されますが、関数が呼び出された後、電話の電子メールクライアントは表示されません
ここに私のコードがあります
メインクラスでは、次の呼び出しを行います
-(void)emailFunction{
...
CommonlyUsed Email = [[CommonlyUsed alloc] init];
[Email sendMail:receipient :CC :BCC :subject :body];
...
}
私の CommonlyUsed.h には、次の名前の IDE があります。
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MessageUI.h>
@interface CommonlyUsed : UIViewController <MFMailComposeViewControllerDelegate>{
CommonlyUsed.m には次のものがあります。
-(void)sendMail:(NSString*)receipient:(NSString*)cc:(NSString*)bcc:(NSString*)subject:(NSString*)body{
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[ composer setMailComposeDelegate:self];
if ( [MFMailComposeViewController canSendMail]){
if (receipient) {
[composer setToRecipients:[NSArray arrayWithObjects:receipient, nil]];
}
if (cc) {
[composer setCcRecipients:[NSArray arrayWithObjects:receipient, nil]];
}
if (bcc) {
[composer setBccRecipients:[NSArray arrayWithObjects:receipient, nil]];
}
if (subject) {
[composer setSubject:subject];
}
[composer setMessageBody:body isHTML:HTMLBody];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if(error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@", [error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
else{
[self dismissModalViewControllerAnimated:YES];
}
}
コードはコンパイルされ、エラーなしで実行されます。何が欠けていますか??