小编yfr*_*cis的帖子

如何接收通过CPDistributedNotificationCenter发布的通知

AppSupportiOS上的私有框架有一个被调用的类CPDistributedNotificationCenter,它似乎支持NSDistributedNotificationCenterOS X上提供的功能的一个子集.

我正在尝试使用此类从后台守护程序发布通知,以便其他进程中的多个客户端可以接收这些通知并对其进行操作.我意识到还有其他选择,包括CPDistributedMessagingCenter或者CFMessagePort,低级马赫端口甚至是达尔文notify_post.如果守护进程不知道客户端,我更喜欢它,并且我希望能够将数据与通知一起传递,并且notify_post不允许这样做.

目前,这就是我在守护进程中所做的事情:

CPDistributedNotificationCenter* center;
center = [CPDistributedNotificationCenter centerNamed:@"com.yfrancis.notiftest"];
[center runServer];
[center postNotificationName:@"hello"];
Run Code Online (Sandbox Code Playgroud)

在客户端:

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];
Run Code Online (Sandbox Code Playgroud)

where Listener是一个实现单个方法的简单类gotNotification:

不幸的是,客户端从未收到"hello"通知.如果我将呼叫中的name参数替换为我可以看到每个通知都发送到客户端的通知中心,但"你好"不是其中之一.addObservernil

我通过观察的拆解得到了我的代码的灵感SpringBoardCPDistributedNotificationCenter.通知显示通过被输送CPDistributedNotificationCenterdeliverNotification:userInfo:其用作垫片NSNotificationCenterpostNotificationName:object:userInfo:.

我在这里错过了什么?

cocoa ipc objective-c ios

4
推荐指数
1
解决办法
1420
查看次数

Sublime Text 2和Terminal

所以我试图通过这个命令从终端启动Sublime Text 2,由Sublime Text文档给出:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,这是行不通的.我从终端收到此错误:

ln: /Users/connorblack/bin/subl: No such file or directory
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?

其他细节:我的Applications文件夹中有SB2.我正在尝试进行RoR开发.

bash terminal sublimetext2

3
推荐指数
1
解决办法
5057
查看次数

标签 统计

bash ×1

cocoa ×1

ios ×1

ipc ×1

objective-c ×1

sublimetext2 ×1

terminal ×1