作者donkeychen (Bad_To_The_Bone)
看板MacDev
标题[问题] 关於不同程式间的NSNotificationCenter
时间Fri Mar 21 15:55:22 2014
大家好
想请问一下
如果我在a程式里面使用
NSNotificationCenter *nc_in_a = [NSNotificationCenter defaultCenter];
在b程式里面使用
NSNotificationCenter *nc_in_b = [NSNotificationCenter defaultCenter];
A与B的bundle id不同
想请教一下
假设
a程式的code有
[nc_in_a addObserver: ..... name:@"same_name" ...];
b程式的code有
[nc_in_b addObserver: ..... name:@"same_name" ...];
nc_in_a 与 nc_in_b
是否会互相干扰呢
观念不是很清楚的部分还请各位指导
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.59.147.226
1F:推 kiii210:bundleid不同 应该就不会了吧 03/21 16:04
2F:→ kiii210:不是有sandbox机制? 我觉得应该不会..有错请楼下更正 03/21 16:05
3F:→ benjenq:创两个Bundle ID,彼此互相玩玩看不就得了? 03/22 01:54
4F:→ whitefur:不会 03/22 12:03
5F:→ uranusjr:每个程式的 NSNotificationCenter 皆各自独立 03/22 19:43
6F:→ donkeychen:感谢大家 我发现我好像贴错code了^^; 抱歉 我要问的是 03/24 14:26
7F:→ donkeychen:NSDistributedNotificationCenter 这种在不同程式间传 03/24 14:26
8F:→ donkeychen:的 03/24 14:27
感谢大家回应
我改了一下问题
假设a里面是
NSDistributedNotificationCenter* nc_in_a = [NSDistributedNotificationCenter
defaultCenter];
b里面是
NSDistributedNotificationCenter* nc_in_b = [NSDistributedNotificationCenter
defaultCenter];
a程式的code有
[nc_in_a addObserver: ..... name:@"same_name" ...];
b程式的code有
[nc_in_b addObserver: ..... name:@"same_name" ...];
假设c程式
NSDistributedNotificationCenter* nc_in_c = [NSDistributedNotificationCenter
defaultCenter];
[nc_in_c postNotificationName:@"same_name" ..];
是不是a b 都会收到呢
看了说明是写
Each task has a default distributed notification center that you access with
the defaultCenter class method. There may be different types of distributed
notification centers. Currently there is a single type—
NSLocalNotificationCenterType. This type of distributed notification center
handles notifications that can be sent between tasks on a
single computer
我自己猜想这边三个
nc_in_a
nc_in_b
nc_in_c
是同一个 会互相影响
(衍申的问题 想请教一下是否有办法看到目前已经add的Observer)
还请大家指点
谢谢
※ 编辑: donkeychen 来自: 210.59.147.226 (03/24 14:40)