I have create program to send mail with my some detail from sqlite database
It is working fine if I am not using attachment but if i uncomment that like i m getting exception like this:
Thread 1: EXC_BAD_ACCESS(code=1, address=0x474e5091
here is My code:
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = (id) self;
NSArray *recipients = [NSArray arrayWithObject:@"chintan_zwt@yahoo.com"];
[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];
I m getting data correctly from database and i m able to display image on screen but problem is only when i attach image to mail
Here in
UIImagePNGRepresentation(u.Img1)
U is an object of User Class (user define class) and Img1 is object of UIImage
First of the
addAttachmentData:mimeType:fileName:method need aNSDataobject, so there is not need o call the bytes method on theNSData.If you try this in you code you can check wether the
UIImagePNGRepresentation()method returns a valid NSData object. Just place a breakpoint on the line and check what the values are in the debugger.