3

メール用アプリで MFMailComposeViewController を提示しています。しかし、ビューは表示されず、上部の SEND および CANCEL ボタンのみが表示されます。

これは、[Email to Subscribe] ボタンをクリックした後に表示されるビューのスクリーン ショットです。

ここに画像の説明を入力

関連するすべてのコードをチェックアウトしました。「MessageUI」フレームワークを追加してインポートしました

MessageUI/MessageUI.h , MessageUI/MFMailComposeViewController.h

次のコードを使用しました:

 - (void)viewWillAppear:(BOOL)animated {

     [self.view setFrame:CGRectMake(0, 62, 320, 418)];

     [APPDELEGATE.window addSubview:self.view];

     [self.navigationController.navigationBar setHidden:NO];
     self.navigationItem.title=@"Free Subscription";
     [super viewWillAppear:animated]; }


 -(void)viewWillDisappear:(BOOL)animated {
     [self.view removeFromSuperview];
     [super viewWillDisappear:animated]; }



     -(IBAction)btnEmailPressed {
         MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
         if (Apicker != nil)
         {

         [Apicker setSubject:@"Free Subscription"];

         [Apicker setMessageBody:@" " isHTML:NO];

         NSArray *toRecipients = [NSArray arrayWithObjects:@"info@xyz.com", nil];
         [Apicker setToRecipients:toRecipients];

         Apicker.mailComposeDelegate = self;

         if([MFMailComposeViewController canSendMail])
         {
             [self presentModalViewController:Apicker animated:YES];
         }
         else
         {

         }
         [Apicker release];
     } }


     -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError
     *)error{

     NSString *message;

     switch (result) {
         case MFMailComposeResultCancelled:
             message =@"You have canceled your email.";
             break;
         case MFMailComposeResultFailed:
             message=@"Your email is failed";
             break;
         case MFMailComposeResultSent:
             message=@"Your email was successfully sent.";
             break;
         case MFMailComposeResultSaved:
             message=@" Your email has been saved";
             break;

         default:
             message=@" Your email is not send";
             break;
     }
     UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"" message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

     [alt show];
     [alt release];

     [self dismissModalViewControllerAnimated:YES];
      }

この問題の理由がわかりませんでした。

ありがとう。

4

3 に答える 3

8

そのIOS 6用

-(void)email{
    MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"xyz@gmail.com", nil]];
        [composer setSubject:@""];

        //    [composer.setSubject.placeholder = [NSLocalizedString(@"This is a placeholder",)];

        [composer setMessageBody:@"" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else {
    }
}
-(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 dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

ちょうど試して

iOS 5 の場合

-(void)email:(id)sender{
    MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"xyz@gmail.com", nil]];
        [composer setSubject:@""];

        //    [composer.setSubject.placeholder = [NSLocalizedString(@"This is a placeholder",)];

        [composer setMessageBody:@"" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:composer animated:YES];
    }
    else {
    }
}
-(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];
    }
}
于 2012-11-29T10:47:21.263 に答える
2

このようにコードを変更してみてください:-

-(IBAction)btnEmailPressed 
{ 
    MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
    if (Apicker != nil)   
    {
        [Apicker setSubject:@"Free Subscription"];
        [Apicker setMessageBody:@" " isHTML:NO];
        NSArray *toRecipients = [NSArray arrayWithObjects:@"info@xyz.com", nil];
        [Apicker setToRecipients:toRecipients];
        Apicker.mailComposeDelegate = self;

       if([MFMailComposeViewController canSendMail])
       {
           [self presentModalViewController:Apicker animated:YES];
       }
       else
       {
            NSString *recipients = @"mailto:info@xyz.com?cc=&subject=";
            NSString *body = @"&body=";

                NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
            email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
         }
         [Apicker release];
     } 
}
于 2012-11-29T10:52:18.887 に答える
0

これら 2 つのデリゲートを.hファイルに追加しMFMessageComposeViewControllerDelegateMFMailComposeViewControllerDelegate

アップデート

     if ([MFMailComposeViewController canSendMail]) {
            appDelegate.imgCapture = [self captureView];
            [appDelegate.imgCapture retain];
            MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
            NSString *mailBody = @"Set Your Body Message";


            [mailComposeViewController setMessageBody:mailBody isHTML:NO];
            mailComposeViewController.mailComposeDelegate = self;
            [self presentViewController:mailComposeViewController animated:YES completion:nil];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
                                                            message:@"You can't send a mail"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
于 2012-11-29T10:27:24.983 に答える