如何让我的iOS应用程序相互通信? [英] How can I make my iOS apps talk to each other?

查看:101
本文介绍了如何让我的iOS应用程序相互通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个iOS应用程序,我需要他们彼此了解。更准确地说,我需要知道是否已经安装了我的应用程序。

I’ve got several iOS apps and I need them to be aware of each other. More precisely, I need to know whether there’s already one of my apps installed.

我考虑过注册自定义URL方案(类似于 my- app-present:// ),以便我可以检查自定义方案是否受支持,如果是,我知道我的设备上已有一个应用程序。但这不起作用,因为这些方案是通过 Info.plist 注册的,并且应用程序在有机会检查其存在之前注册该方案。换句话说,检查总是成功。

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. 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. In other words, the check always succeeds.

然后我考虑在临时目录中创建一个文件,但是 NSTemporaryDirectory()返回应用程序沙箱中的文件夹,因此也不起作用。我也考虑过钥匙串,但看起来每个应用程序在iOS上都有严格单独的钥匙串。

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. I also thought about keychain, but again it looks like each application has strictly separate keychain on iOS.

我不想浏览正在运行的应用程序列表不想使用网络。你知道其他一些技巧吗?

I don’t want to go through the list of running apps and I don’t want to use networking. Do you know some other tricks?

推荐答案

自定义URL方案听起来不错,只要你有一个不同的方案app,例如 my-app-1:// my-app-2:// 。然后(我假设这是你已经知道的)你可以使用 canOpenURL: 检查是否可以处理URL(即,您的应用是安装)。

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://. Then (I assume this is what you already knew) you can use canOpenURL: to check if the URL can be handled (i.e., your app is installed).

这篇关于如何让我的iOS应用程序相互通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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