8

是否可以在两个不同的应用程序之间进行通信,一个在后台运行,另一个在前台运行?如果是,任何人都可以建议如何?

4

2 回答 2

5

是的,可以在 iPhone 中的两个应用程序之间进行通信,但仅限于少数场景。

  1. 可能有一些应用程序需要根据电话等事件发送到后台。在这种情况下,您必须配置您的音频会话对象(基于 Voip 的应用程序)并相应地发送通知。

  2. 前面的例子只是在应用程序之间进行交互,灵活性极低(在一些重要的内置事件上将应用程序发送到后台)。另一种方法是通过 URL Schemes ,苹果有一些内置功能并支持某些应用程序,如邮件.tel 等。但其中一个应用程序将出现在前台。

就像您可以拨打电话号码一样,该电话号码是内置在应用程序中的:-

NSString *phURL= [NSString stringWithFormat:@"tel:%@", [NSString StringWithString:@"1-800-555-1212"]];
NSURL *phoneURL = [NSURL URLWithString:phURL];
[[UIApplication sharedApplication] openURL:phoneURL]];

顺便说一句,如果您需要实现自定义 URL 方案.. 玩得开心。

  1. The other way is through UIDocumentInteractionController which provides in-app support to have interaction between certain files.(Sandbox environment inhibits a complete access or even accesses that can modify data of other application).Like it can be used to preview files in mail app or download attachments.But you cannot modify them for other application , of course you can copy it and modify it for your application.
于 2012-05-15T20:00:49.040 回答
1

我不认为这正是你想要的,但它肯定会让你在应用程序之间进行交互。

https://developer.apple.com/library/IOs/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18

它只是使用 URL 方案来激活命令并在另一个应用程序中打开。只是尽量避免为您自己的应用程序使用苹果默认值。

于 2012-05-15T19:43:15.780 回答