看板 MacDev 關於我們 聯絡資訊
大家好 想請問一下 如果我在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
kiii210:bundleid不同 應該就不會了吧 03/21 16:04
kiii210:不是有sandbox機制? 我覺得應該不會..有錯請樓下更正 03/21 16:05
benjenq:創兩個Bundle ID,彼此互相玩玩看不就得了? 03/22 01:54
whitefur:不會 03/22 12:03
uranusjr:每個程式的 NSNotificationCenter 皆各自獨立 03/22 19:43
donkeychen:感謝大家 我發現我好像貼錯code了^^; 抱歉 我要問的是 03/24 14:26
donkeychen:NSDistributedNotificationCenter 這種在不同程式間傳 03/24 14:26
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)