3

I am trying to attach images to the email and send the email to my email add. The problem is that when i send out an email with 4 or 5 images attached, the app keeps processing for ever and eventually gets hanged and crashes and doesn't send the email. It is working fine with one image. I am thinking it is because of the size of the images combined together. Btw, I am using iOS 6.. How do i restrict the size of the files or images sent? Or there might be other issues involved? The same app is working in ios5....

The email sending portion together with image is:

for (int nCtr = 0; nCtr < [Pix count]; nCtr++) {
            UIImageView *imageV = [Pix objectAtIndex:nCtr];
            if (imageV.image) {
                NSData *imageData = UIImagePNGRepresentation(imageV.image);
                NSString *strFileName = [NSString stringWithFormat:@"MyPicture-%d.jpeg",nCtr];

                NSString *strFormat = [NSString stringWithFormat:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName];
                NSString *strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName];
                NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
                                         strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];

                [images addObject:vcfPart];
            }
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • http://stackoverflow.com/questions/4394491/how-to-compress-resize-image-on-iphone-os-sdk-before-uploading-to-a-server – iDev Nov 09 '12 at 08:30
  • the same app is working fine in ios5.... – lakshmen Nov 09 '12 at 08:47
  • So if you reduce the number of images to 2, is it working fine in iOS 6? if that is the case then it should be due to the memory warning. for that you might have to use some compression or resize option. – iDev Nov 09 '12 at 08:49
  • 2 images can.. Three images onwards got problem.... but ios5 sending 5 images also is possible... – lakshmen Nov 09 '12 at 09:13
  • hi... any solution? what abt changing the maximum size of the files combined sent together? – lakshmen Nov 09 '12 at 09:41
  • other than compressing? any other solution? – lakshmen Nov 09 '12 at 10:43
  • I am not sure about anything other than resizing. Check if there are any other compression mechanisms available so that you can zip it and send. – iDev Nov 09 '12 at 19:12
  • but my point is that it could not a resizing issue since the same thing is working fine in ios5, but ios 6 then it has a issue... – lakshmen Nov 09 '12 at 19:16
  • Check the image size in both OSs. Is there any big difference? – iDev Nov 09 '12 at 19:17
  • i dun think it is an issue with the OSs.. something to do with the ios6.. Have look at this post: http://forums.imore.com/ios-6-forum/240955-cant-send-photos-over-wi-fi.html – lakshmen Nov 12 '12 at 03:04
  • @lakesh still have a problem ?? – Omarj Nov 14 '12 at 13:24

2 Answers2

0

There is something wrong in your code i can't figure but you can use this project it is

work will with multi attach file and it handle all cases.

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            NSLog(@"Mail not sent.");
            break;
    }
        // Remove the mail view
    [self dismissModalViewControllerAnimated:YES];
}
Omarj
  • 1,151
  • 2
  • 16
  • 43
  • sending mail is ok.. sending mail with image is the problem... Then how can you answer be correct? – lakshmen Nov 13 '12 at 10:06
  • i use the project and attached multi image and it is work with me, and there is an code i post it above handle every case to let u know what happened to your email. so what your problem with that ??? – Omarj Nov 13 '12 at 10:09
  • it works fine with ios5.. in ios6, when i attach more than 3 images, it hangs up and the app is not progressing at all... – lakshmen Nov 13 '12 at 10:11
  • wait a s, i will try it and tell u what happen with me. – Omarj Nov 13 '12 at 10:12
  • so how did u try? any problem? – lakshmen Nov 13 '12 at 13:58
  • sorry, but device not available for now :( so u need to wait until it is reachable to me. but i'm sure it is work because my project was send multi-object at the same email to multi-Email address and it is work. – Omarj Nov 13 '12 at 14:04
0

Just change it from PNG format to JPEG format.

for (int nCtr = 0; nCtr < [arrPix count]; nCtr++) {
            UIImageView *imageV = [arrPix objectAtIndex:nCtr];
            if (imageV.image) {
                NSData *imageData = UIImageJPEGRepresentation(imageV.image, 0.9);
                NSString *strFileName = [NSString stringWithFormat:@"MyPicture-%d.jpeg",nCtr];

                NSString *strFormat = [NSString stringWithFormat:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName];
                NSString *strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName];
                NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
                                         strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];

                [parts addObject:vcfPart];
            }
        }

It seems that ios6 limits the size of the images...Hence it is better to compress the image...

lakshmen
  • 28,346
  • 66
  • 178
  • 276