2012-07-21 3 views
1

전자 메일을 통해 아래 코드를 사용하여 장치 로그 파일을 보내려고합니다. iPod touch 및 iPad에서 이메일을 Wi-Fi 네트워크로 보낼 수 있습니다. 그러나 3G 네트워크에서 iPhone으로 이메일을 보내려고 할 때 충돌이 발생합니다. 나는 코드를 데뷔하고 presentModalViewController를 수행하는 동안 이것이 충돌하고 있음을 알게되었다.3G에서 이메일을 보내는 동안 현재의 모니터 뷰 컨트롤러가 충돌 함

이 문제를 해결하는 방법을 알려주십시오.

- (IBAction)sendEmail:(id)sender 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 
  
    // Set the subject of email 
    [picker setSubject:@"Debug Log"]; 
  
    // Add email addresses 
    [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]]; 
  
    // Fill out the email body text 
    NSString *emailBody = @"Debug Log content…… "; 
  
    // This is not an HTML formatted email 
    [picker setMessageBody:emailBody isHTML:NO]; 
  
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     
NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *logPath = [documentsDirectory   
stringByAppendingPathComponent:@"console.log"]; 
NSData *data = [NSData dataWithContentsOfFile:logPath]; 
    [picker addAttachmentData:data mimeType:@"text/xml" fileName:@"console.log"]; 
  
    // Show email view  
    [self presentModalViewController:picker animated:YES];//app crash 
  
    // Release picker 
    [picker release]; 
} 
  
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // Called once the email is sent 
    // Remove the email view controller 
    [self dismissModalViewControllerAnimated:YES]; 
} 

답변

3

메일을 보내기 전에 이메일이 iOS 장비에서 구성되어 있는지 확인하십시오.

다음과 같이 메일을 보내기 전에 코드를 통해 메일을 보낼 수있는 기능을 확인할 수 있습니다.

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
if (mailClass != nil) 
{ 
    if ([mailClass canSendMail]) 
    { 
     [self presentModalViewController:YOURMAILCOMPOSER animated:YES]; 
    } 
} 

이도 메일 계정을 설정하도록 말하는 당신에게 당신의 사용자에 대해 자동으로 생성 된 경고보기를 줄 것이다 :

- (IBAction)sendEmail:(id)sender 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 
  
    // Set the subject of email 
    [picker setSubject:@"Debug Log"]; 
  
    // Add email addresses 
    [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]]; 
  
    // Fill out the email body text 
    NSString *emailBody = @"Debug Log content…… "; 
  
    // This is not an HTML formatted email 
    [picker setMessageBody:emailBody isHTML:NO]; 
  
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     
NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *logPath = [documentsDirectory   
stringByAppendingPathComponent:@"console.log"]; 
NSData *data = [NSData dataWithContentsOfFile:logPath]; 

    [picker addAttachmentData:data mimeType:@"text/xml" fileName:@"console.log"]; 
  
    // Show email view  
Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
  if (mailClass != nil) { 
    // We must always check whether the current device is configured for sending emails 
    if ([mailClass canSendMail]) { 
      [self presentModalViewController:picker animated:YES]; 
    } else { 
      //do something 
    } 
  } else { 
   //do something 
  } 
    // Release picker 
    [picker release]; 
} 

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // Called once the email is sent 
    // Remove the email view controller 
    [self dismissModalViewControllerAnimated:YES]; 
} 
0

간단한 대답이 코드로 presentModalViewController에 전화를 캡슐화하는 것입니다 계속하기 전에 ...