Reputation: 11
I am sending a NSMutableString through the body of an email. It will not work because it says senderString cannot by statically located. Help?
NSMutableString *senderString = [[NSMutableString alloc] init];
NSURL *mailURL = [NSURL URLWithString: @"mailto:[email protected][email protected]&subject=My%20Subject%20Line&body=%@"], senderString;
[[UIApplication sharedApplication] openURL: mailURL];
Upvotes: 1
Views: 345
Reputation: 23001
The problem is your inclusion of senderString
on the end of the line declaring the mailURL
. I'm assuming you're trying to set the senderString
as the body of the email.
If that is the case, you'll need to do something like this:
NSString *urlString = [NSString stringWithFormat:
@"mailto:[email protected][email protected]&subject=My%%20Subject%%20Line&body=%@",
senderString];
And it's worth mentioning that if the senderString
isn't already percent escaped as required for use in a url, you'll need to do something like this first (i.e. before the stringWithFormat
call):
senderString = [senderString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Then you can just construct the mailURL
like this:
NSURL *mailURL = [NSURL URLWithString:urlString];
Update: I've added escaping for the percent in %20
and added a recommendation to escape the senderString
parameter, as suggested by rmaddy.
Upvotes: 3