简体   繁体   English

如何让我的 iOS 应用程序相互通信?

[英]How can I make my iOS apps talk to each other?

I've got several iOS apps and I need them to be aware of each other.我有几个 iOS 应用程序,我需要它们相互了解。 More precisely, I need to know whether there's already one of my apps installed.更准确地说,我需要知道是否已经安装了我的应用程序之一。

I thought about registering a custom URL scheme (something like my-app-present:// ), so that I could check whether the custom scheme is supported and if yes, I would know there's already one of my apps on the device.我考虑注册一个自定义 URL 方案(类似于my-app-present:// ),以便我可以检查是否支持自定义方案,如果是,我会知道设备上已经有我的一个应用程序。 But that doesn't work, because the schemes are registered through Info.plist and the app registers the scheme before it has a chance to check for its existence.但这不起作用,因为方案是通过Info.plist注册的,并且应用程序会在有机会检查其存在之前注册该方案。 In other words, the check always succeeds.换句话说,检查总是成功的。

Then I thought about creating a file in the temporary directory, but NSTemporaryDirectory() returns a folder inside the application sandbox, so that wouldn't work either.然后我考虑在临时目录中创建一个文件,但是NSTemporaryDirectory()在应用程序沙箱中返回一个文件夹,所以这也行不通。 I also thought about keychain, but again it looks like each application has strictly separate keychain on iOS.我也考虑过钥匙串,但看起来每个应用程序在 iOS 上都有严格独立的钥匙串。

I don't want to go through the list of running apps and I don't want to use networking.我不想通过正在运行的应用程序列表 go 并且我不想使用网络。 Do you know some other tricks?你知道其他一些技巧吗?

The custom URL scheme method sounds fine, as long as you have a different scheme for every app, for example my-app-1:// and my-app-2:// .自定义 URL 方案方法听起来不错,只要您对每个应用程序都有不同的方案,例如my-app-1://my-app-2:// Then (I assume this is what you already knew) you can use canOpenURL: to check if the URL can be handled (ie, your app is installed).然后(我假设这是您已经知道的)您可以使用canOpenURL:检查是否可以处理 URL(即,您的应用程序已安装)。

If by "talk to each other" you meant you just want to detect whether other app has been installed or not then iHasApp is an open source iOS framework could come in handy.如果通过“互相交谈”意味着您只想检测是否已安装其他应用程序,那么 iHasApp 是一个开源 iOS 框架可以派上用场。 I haven't used it yet.我还没用过。 but from the description it appears to be a good choice.但从描述来看,它似乎是一个不错的选择。

http://www.ihasapp.com/documentation/Classes/iHasApp.html http://www.ihasapp.com/documentation/Classes/iHasApp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM