2011-10-21 45 views
-1

我正在模擬器中工作,但是當我們嘗試在設備中打開時,程序正在終止。打開設備上的MFMailComposeViewController時出現問題,在模擬器中工作。

Plz suggess me fast。

MFMailComposeViewController *mail=[[MFMailComposeViewController alloc]init]; 
mail.mailComposeDelegate=self; 
[mail setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; 

//[self becomeFirstResponder]; 
mail.navigationBar.tintColor=[UIColor blackColor]; 
[self presentModalViewController:mail animated:YES]; 

回答

0

你的代碼看起來不錯,但你檢查,如果設備可以發送郵件:

if ([MFMailComposeViewController canSendText]) { 
    MFMailComposeViewController *mail=[[MFMailComposeViewController alloc]init]; 
    mail.mailComposeDelegate=self; 
    [mail setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; 

    mail.navigationBar.tintColor=[UIColor blackColor]; 
    [self presentModalViewController:mail animated:YES]; 
    [mail release], mail = nil; 
} else { 
    // show message to the use that he can't send an email. 
} 
+0

謝謝,但它再次終止在設備,但不是在模擬器。 – Rahul

+0

請提供錯誤消息,設備的iOS版本和堆棧跟蹤。 – rckoenes

0

你實現你的代碼MFMailComposeViewControllerdelegate方法?

#pragma mark -------------------------------------------- 
#pragma mark MFMailComposeViewController delegate Methods 

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 
    switch (result) { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail send canceled."); 
      /* 
      Execute your code for canceled event here ... 
      */ 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved."); 
      /* 
      Execute your code for email saved event here ... 
      */ 
      break; 
     case MFMailComposeResultSent: { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sent" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      alert.tag = 1; 
      alert.delegate = self; 
      [alert show]; 
      [alert release]; 
      break; 
     } 
     case MFMailComposeResultFailed: { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sending Failed" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      alert.tag = 2; 
      alert.delegate = self; 
      [alert show]; 
      [alert release]; 
      break; 
     } 
     default: 
      break; 
    } 
    [controller dismissModalViewControllerAnimated:YES];//dismissing modal view controller 
} 
+0

我加了,但又不能在設備中工作 – Rahul

+0

你是否在你的班級里加了這段代碼 –

+0

是我加了但是 – Rahul

0
if ([MFMessageComposeViewController canSendText]) 

你的問題是在這裏。您正試圖檢查設備是否可以發送短信,而不是發送電子郵件。你應該嘗試使用

if([MFMailComposeViewController canSendMail]) 

的問題可能是您的設備沒有配置任何帳戶在mail.Please一次檢查。

+0

謝謝,但我很抱歉地說,它終止在設備。 – Rahul

+0

從http://developer.apple.com/library/ios/#samplecode/MailComposer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008865下載示例代碼,看看它是否適用於設備。 – Nareshkumar

+0

現在感謝兄弟的工作 – Rahul

相關問題