 |
 |
Weird NSURL and NSString Problems
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey guys,
Im trying to launch Mail.app using NSWorkspace. So I use the following code:
Code:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:you@there.com?Subject=Hello%20There&Body=Hi%20There"]];
This opens fine in Mail.app and fills in the appropriate fields with spaces. But when I try this:
Code:
NSString *subject = [NSString stringWithFormat:@"Tag%20Registration"];
NSString *body = [NSString stringWithFormat:@"Body"];
[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?Subject=%@&Body=%@", [emailAddressCell stringValue], subject, body]]];
If I use the above code, when it launches Mail.app, the subject is shown as TagRegistration. With no space. How would I go about adding spaces properly?
Thanks,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
[NSString stringWithFormat:@"somethin%20some"];
isn't what you want...
just set the string equal to whatever you want, like so:
NSString * subject = @"Tag Registration";
should work fine.
the thing is that cocoa looks at the % as a format thing... %d and then another argument prints the argument as a decimal, and such... I don't think %2 or %20 is one of the options, so that's probably why you've got an error.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hmm,
This code didn't seem to work, Mail wouldn't open:
Code:
- (void)openMail:(id)sender
{
NSString *subject = @"Tag Registration";
NSString *body = @"Body Is Here";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?Subject=%@&Body=%@", [emailAddressCell stringValue], subject, body]]];
}
But, if there is no spaces, it works fine.
Any ideas appreciated,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
You can't use "%20" in a printf-style format string because the percent character is what identifies the places where variables are to be inserted. To include a literal percent character, use "%%".
Since your URL is constructed partially from user-entered text, though, it'd be better to do your percent-escaping after you construct the string. So, let "Tag%20Registration" be "Tag Registration", construct your URL string, and then use -stringByAddingPercentEscapesUsingEncoding: (see NSURL.h) to turn it into a URL-safe string before making an NSURL from it.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey thanks,
That did the trick.
Thanks again,
Oliver
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|