2012-09-21 67 views
0

發送郵件隨着Attachement我已創建程序EXC_BAD_ACCESS在iPhone

它,如果我不使用連接工作正常與我的一些細節,從SQLite數據庫發送郵件,但如果我取消,像即時得到異常喜歡這個:

Thread 1: EXC_BAD_ACCESS(code=1, address=0x474e5091 

這裏是我的代碼:

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init]; 

    mailView.mailComposeDelegate = (id) self; 

    NSArray *recipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [mailView setToRecipients:recipients]; 
    [mailView setSubject:@"Try Mail From User Application"]; 

    NSString *body = [[NSString alloc] initWithFormat:@"First Name : %@ <br>",lblFirstName.text]; 

    body = [body stringByAppendingFormat:@"Last Name : %@<br>",lblLastName.text]; 
    body = [body stringByAppendingFormat:@"Username : %@<br>",lblUsername.text]; 
    body = [body stringByAppendingFormat:@"Password : %@<br>",lblPassword.text]; 
    body = [body stringByAppendingFormat:@"Birthdate : %@<br>",lblBD.text]; 

    [mailView addAttachmentData:[UIImagePNGRepresentation(u.Img1) bytes] 
         mimeType:@"image/png" 
         fileName:@"a.png"]; 

    [mailView setMessageBody:body isHTML:YES]; 

    [self presentModalViewController:mailView animated:YES]; 

我米數據庫獲取正確的數據和即時通訊能夠在屏幕上顯示的圖像,但問題是隻磨片NI附加圖像在

UIImagePNGRepresentation(u.Img1) 

U是用戶類的目的郵件

這裏(用戶定義類)和IMG1是UIImage的

的對象

回答

0

addAttachmentData:mimeType:fileName:方法首先需要一個NSData對象,所以不需要調用NSData上的字節方法。

如果您在代碼中嘗試此操作,則可以檢查UIImagePNGRepresentation()方法是否返回有效的NSData對象。只需在線上放置一個斷點並檢查調試器中的值。

NSData *imageDate = UIImagePNGRepresentation(u.Img1); 
[mailView addAttachmentData:imageDate mimeType:@"image/png" fileName:@"a.png"]; 
+0

感謝它正在完美地工作。 – CRDave