如何使用 xcode 连接或打开另一个应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6593252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:25:36  来源:igfitidea点击:

how to connect or open another aplication with xcode?

objective-cxcodexcode4iphone-4

提问by user4951

now.. I was making a program.. but I want to make the program connected to another application or make an application running in my application.. such as, when people want to sign up to my application, I want to open safari application or make it running in my application? how can I do so? is there anyone help me with a sample code?

现在..我正在制作一个程序..但我想让这个程序连接到另一个应用程序或让一个应用程序在我的应用程序中运行..例如,当人们想注册我的应用程序时,我想打开safari应用程序或者让它在我的应用程序中运行?我该怎么做?有没有人帮我提供示例代码?

Or for example, in yelp, clicking some button will open google map application and point direction from our location to the next

或者例如,在 yelp 中,单击某个按钮将打开 google 地图应用程序并指出从我们位置到下一个位置的方向

how would I do so?

我该怎么做?

回答by David

Depends on your platform. For OSX, NSAppleScriptis your solution. It allows you to interact with other scriptable programs like Safari, iTunes, Finder, etc.

取决于你的平台。对于 OSX,NSAppleScript是您的解决方案。它允许您与其他可编写脚本的程序(如 Safari、iTunes、Finder 等)进行交互。

For iPhone, your question has been asked / answered before: Open Google Maps from iPhone and show route

对于 iPhone,您的问题之前曾被问过/回答过:从 iPhone 打开谷歌地图并显示路线

回答by André Moruj?o

If what you want is a generic way to launch anyapp on iOS, there is no way to do it (at least using the official APIs).

如果您想要的是在 iOS上启动任何应用程序的通用方式,则没有办法做到(至少使用官方 API)。

It is possible, however, to launch a few apps based on their supported URL schemes.

但是,可以根据支持的 URL 方案启动一些应用程序。

To do this, you would do something like:

为此,您将执行以下操作:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

This will allow you to open a few native apps like Safari, Mail, Maps, Messages, App Store, etc (and depending on the URL, it may not only open the app but also perform some app-specific action).

这将允许您打开一些本机应用程序,例如 Safari、邮件、地图、消息、App Store 等(并且根据 URL,它不仅可以打开应用程序,还可以执行一些特定于应用程序的操作)。

There are a few repositories that list both native and third-party apps and their known URL schemes, such as these:

有一些存储库列出了本机和第三方应用程序及其已知的 URL 方案,例如: