Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to receive notifications posted via CPDistributedNotificationCenter
    text
    copied!<p>The private <code>AppSupport</code> framework on iOS has a class called <code>CPDistributedNotificationCenter</code> which appears to support a subset of the functionality provided by <code>NSDistributedNotificationCenter</code> on OS X.</p> <p>I'm attempting to use this class to post notifications from a background daemon such that multiple clients in other processes can receive these notifications and act on them. I realize there are other options, including <code>CPDistributedMessagingCenter</code> or <code>CFMessagePort</code>, low level mach ports or even darwin's <code>notify_post</code>. I'd prefer it if the daemon had no knowledge of the clients however, and I'd like to be able to pass data along with the notification, and <code>notify_post</code> does not allow this.</p> <p>Currently, this is what I am doing in the daemon:</p> <pre><code>CPDistributedNotificationCenter* center; center = [CPDistributedNotificationCenter centerNamed:@"com.yfrancis.notiftest"]; [center runServer]; [center postNotificationName:@"hello"]; </code></pre> <p>And in the client:</p> <pre><code>CPDistributedNotificationCenter* center; center = [CPDistributedNotificationCenter centerNamed:@"com.yfrancis.notiftest"]; [center startDeliveringNotificationsToMainThread]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver:[Listener new] selector:@selector(gotNotification:) name:@"hello" object:nil]; </code></pre> <p>where <code>Listener</code> is a simple class that implements a single method <code>gotNotification:</code> </p> <p>Unfortunately, the client never receives the 'hello' notification. If I replace the <code>name</code> argument in the <code>addObserver</code> call with <code>nil</code> I can see every notification delivered to the client's notification center, but 'hello' is not one of them.</p> <p>I got the inspiration for my code by looking at a disassembly of <code>SpringBoard</code> and <code>CPDistributedNotificationCenter</code>. Notifications appear to be delivered via <code>CPDistributedNotificationCenter</code>'s <code>deliverNotification:userInfo:</code> which acts as a shim for <code>NSNotificationCenter</code>'s <code>postNotificationName:object:userInfo:</code>.</p> <p>What am I missing here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload