zarapps
zarapps

Reputation: 11

Xcode: Sending screenshot of MKmapView to e-mail attachment

I'm using Xcode 4 Beta to display User Location on a Map which works fine. next I take a screen shot of the map and display it as a attachment on an e-mail(the code below attaches the map screen shot to e-mail but the image sent is only grey grid lines)

Can you please help, is this a restriction placed google?or is there an alternative way to do this

p.s I tried taking a screenshot of map manually it worked on my iphone 4.

-(IBAction)buttonPress:(id)sender {

UIGraphicsBeginImageContext(mapView.frame.size);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData * imageData = UIImageJPEGRepresentation(image,2.0);


if 
   ( [MFMailComposeViewController canSendMail] ) {
   MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.delegate = self;
   [mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"attachment.jpng"];

    /* Configure other settings */
        [mailComposer setSubject:@"subject here"];
       [mailComposer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]];


    [self presentModalViewController:mailComposer animated:YES];
           }

}


I've played around with the code eventually got it working, but another issue I'm facing is the e-mail refuses to get sent and is placed in my unsent messages box in my e-mail. The hotmail account gives me an error message saying "a copy has been placed in your outbox. sending the message content to server failed"

CAN YOU PLEASE HELP

COULD THIS BE BECAUSE OF COPY RIGHT ISSUES WITH GOOGLE MAP?OR AN ERROR WITH CODE

Upvotes: 1

Views: 1359

Answers (1)

user1162866
user1162866

Reputation: 33

As far as I know you should use NUIImagePNGRepresentation() instead of UIImageJPEGRepresentation(image,2.0); because screenshots are PNG's.

Other than that I don't know what could be wrong with your code.

Upvotes: 1

Related Questions