[問題] 關於不同程式間的NSNotificationCenter

看板MacDev作者 (Bad_To_The_Bone)時間11年前 (2014/03/21 15:55), 編輯推噓1(107)
留言8則, 5人參與, 最新討論串1/1
大家好 想請問一下 如果我在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

03/21 16:04, , 1F
bundleid不同 應該就不會了吧
03/21 16:04, 1F

03/21 16:05, , 2F
不是有sandbox機制? 我覺得應該不會..有錯請樓下更正
03/21 16:05, 2F

03/22 01:54, , 3F
創兩個Bundle ID,彼此互相玩玩看不就得了?
03/22 01:54, 3F

03/22 12:03, , 4F
不會
03/22 12:03, 4F

03/22 19:43, , 5F
每個程式的 NSNotificationCenter 皆各自獨立
03/22 19:43, 5F

03/24 14:26, , 6F
感謝大家 我發現我好像貼錯code了^^; 抱歉 我要問的是
03/24 14:26, 6F

03/24 14:26, , 7F
NSDistributedNotificationCenter 這種在不同程式間傳
03/24 14:26, 7F

03/24 14:27, , 8F
03/24 14:27, 8F
感謝大家回應 我改了一下問題 假設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)
文章代碼(AID): #1JA_1joh (MacDev)
文章代碼(AID): #1JA_1joh (MacDev)