从Mac App获取URL

时间:2011-03-31 22:08:44

标签: objective-c xcode macos interface-builder

我会在IBAction中提供什么来获取打开浏览器的URL(电子邮件或HTTP)?

谢谢!

1 个答案:

答案 0 :(得分:2)

在Safari中打开页面:

NSURL *url = [[NSURL alloc] initWithString: @"http://www.google.com/"];
[[UIApplication sharedApplication] openURL:url]

在Mail中创建新邮件:

NSString *subject = @"The subject";
NSString *body = @"The message";
NSString *address = @"mail@address.com";
NSString *cc = @"mail@address.com";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];