6

An app can make internal use of NSNotificationCenter for different parts to communicate with each other, but can this be extended such that differing apps can use it to communicate?

Edit: sorry for the confusion about iOS versus OSX. I only added the iOS tag, I don't know how/who/why an objective-c tag also got added, it wasn't me.

Nate
  • 31,017
  • 13
  • 83
  • 207
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • 3
    You're asking about iOS, and the answer's already there. For Mac OS X though, `NSDistributedNotificationCenter` posts notifications across process boundaries. – Jonathan Grynspan Dec 15 '11 at 22:38

3 Answers3

5

Sorry for a brief answer but in this case that's all there is to it - no they cannot.

You can register to handle a URL type and then launch pass some data that way.

Nick
  • 8,483
  • 10
  • 46
  • 65
  • So different apps can communicate with each other via URLs? Is this the same mechanism as being launched via a URL or different? (what if it were two background apps wanting to communicate?) – Gruntcakes Dec 15 '11 at 22:24
  • I just meant to launch another app and pass. You didn't offer any details about what you are trying to do. Nor did you note that you are trying to do work with 2 "background" apps. I think what MrMusic means and what might be your best option is to use Remote notifications but that requires you have a notification server or use a service to host your notifications and also that the user has both apps installed and that each is opted in for notifications. – Nick Dec 15 '11 at 22:33
2

Nick's answer is certainly correct, but if you're looking for an alternative to NSNotificationCenter, that works between processes, you can try using the Darwin notification mechanism in CoreFoundation.framework. This works between processes, if you use the Darwin notification center.

See example here on Stack Overflow

... and another one with an example callback

Note that I have not used this in any apps on the iTunes App Store. These APIs are not private, however Apple certainly can reject usage of whatever they like, even if it's not a private API. I just offer this solution as a possibility, without being able to predict App Store acceptibility, or even knowing whether you (or others reading this page) need to submit their apps to the App Store.

I'll also link to this similar question (currently unsolved)

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
0

I think you need a server to handle the communication between two apps.

Say you want app A and app B to communicate with each other. Have both apps periodically report their "locations" to a server S. Also both apps should be listening to S.

Not sure how effectively apps running in the background can listen for data from a server.

Might be helpful to look into how iOS instant messaging apps work. Perhaps there's some open source projects that help with this (and can be adapted to your needs).

SundayMonday
  • 19,147
  • 29
  • 100
  • 154