1

我创建了这个名为 MailComposeViewController 的实用程序类,我正在从其他视图控制器中调用这个类,邮件 Composer 在模拟器上正常工作,但在设备上崩溃。

这样我调用函数

       NSLog(@"Mail");
    MailComposeViewController *mailComposer =[[MailComposeViewController alloc]init];
    [mailComposer showPicker:self andImage:md.Img_savedImageAfterEffect];

下面是我的实用程序类,其中包含发送邮件功能的代码

      #import "MailComposeViewController.h"

      UIViewController *Controller;
      @implementation MailComposeViewController


      -(void)showPicker:(id)viewController andImage:(UIImage*)image;
     {
         Controller = viewController;

           Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
         if (mailClass != nil)
        {
             // We must always check whether the current device is configured for sending emails
            if ([mailClass canSendMail])
           {
               [self displayComposerSheet:viewController andImage:image];
           }
           else
           {
               //[self launchMailAppOnDevice];
              [self displayComposerSheet:viewController andImage:image];
          }
      }
     else
     {
        //[self launchMailAppOnDevice];
        [self displayComposerSheet:viewController andImage:image];
     }
   }
   -(void)displayComposerSheet:(id)viewController andImage:(UIImage*)image
   {
      MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
     picker.mailComposeDelegate = self;


     NSData *myData = UIImageJPEGRepresentation(image,0.9);
     [picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@""];

      picker.modalPresentationStyle = UIModalPresentationFormSheet;
      picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

     [viewController presentModalViewController:picker animated:YES];
    [picker release];
  }
      // 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
  {
      //message.hidden = NO;
     // Notifies users about errors associated with the interface
     switch (result)
     {
         case MFMailComposeResultCancelled:
         // message.text = @"Result: canceled";
         break;
         case MFMailComposeResultSaved:
         // message.text = @"Result: saved";
         break;
         case MFMailComposeResultSent:
         //message.text = @"Result: sent";
         break;
         case MFMailComposeResultFailed:
         // message.text = @"Result: failed";
         break;
        default:
            // message.text = @"Result: not sent";
        break;
     }
   [Controller dismissModalViewControllerAnimated:YES];
 }


  - (void)viewDidLoad
   {
         [super viewDidLoad];
     // Do any additional setup after loading the view.
  }

  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }

  @end

崩溃快照

  Crash Report
  UIKit`-[UIViewController presentModalViewController:animated:]:
  0x3a4d5238:  push   {r7, lr}
 0x3a4d523a:  mov    r7, sp
 0x3a4d523c:  sub    sp, #4
 0x3a4d523e:  movw   r1, #18934
    0x3a4d5242:  mov.w  r9, #0
  0x3a4d5246:  movt   r1, #525
  0x3a4d524a:  str.w  r9, [sp]
  0x3a4d524e:  add    r1, pc
  0x3a4d5250:  ldr    r1, [r1]
   0x3a4d5252:  blx    0x3a734ce4                ; symbol stub for: 
    -[_UIHostedTextServiceSession    dismissTextServiceAnimated:]
  0x3a4d5256:  add    sp, #4
  0x3a4d5258:  pop    {r7, pc}
  0x3a4d525a:  nop    

View Controller 和 mailController 的实例打印在控制台上打印 viewController 的描述:打印选择器的描述:(MFMailComposeViewController *)picker =

4

0 回答 0