UPDATE: I just found a similar post here: http://stackoverflow.com/questions/730101/how-do-i-encode-in-a-url-in-an-html-attribute-value
Please consider the code below: I try to send an email message from within my iPhone app. The problem I encounter is that I want to put a URL in the body of the email. This URL contains two ampersands. I am encoding all the strings using "stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding", but the URL ends up in my new mail messagd truncated after the first ampersand. IE: "http://www.mydomain.nl/?cm=79&ctime=1246572000&cid=4772" becomes "http://www.mydomain.nl/?cm=79".
Any suggestion what I could do to escape?
NSString *eMailSubject = @"My Subject";
NSString *encodedSubject = [[NSString alloc] initWithString:[eMailSubject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *eMailBody = @"http://www.mydomain.nl?cm=79&ctime=1246572000&cid=4772";
NSString *encodedBody = [[NSString alloc] initWithString:[eMailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *urlString = [[NSString alloc] initWithString:[NSString stringWithFormat:@"mailto:?subject=%@&body=%@", encodedSubject, encodedBody]];
NSString *encodedURL = [[NSString alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [[NSURL alloc] initWithString:encodedURL];
[[UIApplication sharedApplication] openURL:url];