从Mac应用程序启动野生动物园 [英] Launch safari from a Mac application

查看:110
本文介绍了从Mac应用程序启动野生动物园的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启动Safari浏览器或用户的默认浏览器,将其指向Mac应用程序中的特定地址?

How can I launch the Safari browser or the user's default browser pointing it to a specific address from within my Mac application?

我正在使用Objective-C作为编程语言.

I am using Objective-C as the programming language.

谢谢.

推荐答案

在shell中,您可以将open命令与URL作为参数一起使用,并负责在默认浏览器中打开该URL.

From a shell you can use the open command with a URL as a parameter, and that takes care of opening that URL in the default browser.

因此,您应该能够使用system()或类似的fork()/exec()代码执行相同的操作.

So you should be able to use system() or similar fork()/exec() code to do the same.

nb:open还将打开其他类型的文件/URL,因此请确保它确实是您要打开的Web URL,否则可能存在安全问题.

nb: open will also open other sorts of files / URLs, too, so make sure it really is a web URL you're trying to open otherwise you've got a probable security problem.

使用Objective C的方法似乎是:

The Objective C way of doing it appears to be:

[[NSWorkspace sharedWorkspace] openURL:url];

其中url是指向NSURL对象的指针

where url is a pointer to an NSURL object

这篇关于从Mac应用程序启动野生动物园的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆