TLDR: Is it possible to send realtime messages or notifications between iOS App and it\'s Extension?
I\'m writing an iOS App with an extension
TLDR: No, but there's a hack
There's no true interprocess communication for iOS apps, with or without extensions. NSDistributedNotification
still hasn't made the trip from OS X to iOS, and probably won't.
With some extension types you can open URLs via NSExtensionContext
and use them to pass data to an app that handles the URL. This brings the app to the foreground, which doesn't sound like what you want.
There is a hack that might get you what you need, though.
NSFileCoordinator
to do coordinated writes to the file.NSFilePresenter
on an object that wants to know about changes to the file, and make sure to call [NSFileCoordinator addFilePresenter:someObject]
presentedItemDidChange
method on your file presenter.If you do all of this right, you can write to this file from either the app or the extension, and then have presentedItemDidChange
be automatically called in the other one. As a bonus you can of course read the contents of that file, so you can pass arbitrary data back and forth.