77
88#import " CODistributedNotificationCenter.h"
99
10- /* *
11- * @group iOS
12- * @abstract A fake distributed notification center that operates locally.
13- *
14- * This makes possible to support NSDistributedNotificationCenter API on iOS.
15- *
16- * On macOS, we use it to keep multiple store instances (using the same UUID)
17- * in sync, accross processes and inside the current process. On iOS, this is
18- * the same, except we don't support the 'accross processes' case.
19- *
20- * Note: A store cannot be accessed by multiple applications on iOS, due to the
21- * sandboxing restrictions.
22- *
23- * See also COSQLiteStore and COUndoTrackStore.
24- **/
2510@implementation CODistributedNotificationCenter
2611
2712static CODistributedNotificationCenter *defaultCenter = nil ;
@@ -39,13 +24,50 @@ + (CODistributedNotificationCenter *)defaultCenter
3924 return defaultCenter;
4025}
4126
42- - (void )postNotificationName : (NSString *)aName
43- object : (NSString *)aSender
44- userInfo : (NSDictionary *)userInfo
27+ - (void )addObserver : (id )observer
28+ selector : (SEL )aSelector
29+ name : (nullable NSNotificationName )aName
30+ object : (nullable NSString *)anObject
31+ {
32+ #if !(SANDBOXED) && !(TARGET_OS_IPHONE)
33+ [[NSDistributedNotificationCenter defaultCenter ]
34+ addObserver: observer
35+ selector: aSelector
36+ name: aName
37+ object: anObject];
38+ #else
39+ [[NSNotificationCenter defaultCenter ]
40+ addObserver: observer
41+ selector: aSelector
42+ name: aName
43+ object: anObject];
44+ #endif
45+ }
46+
47+ - (void )removeObserver : (id )observer {
48+ #if !(SANDBOXED) && !(TARGET_OS_IPHONE)
49+ [[NSDistributedNotificationCenter defaultCenter ] removeObserver: observer];
50+ #else
51+ [[NSNotificationCenter defaultCenter ] removeObserver: observer];
52+ #endif
53+ }
54+
55+ - (void )postNotificationName : (nullable NSNotificationName )aName
56+ object : (nullable NSString *)aSender
57+ userInfo : (nullable NSDictionary *)userInfo
4558 deliverImmediately : (BOOL )deliverImmediately
4659{
4760#if !(SANDBOXED) && !(TARGET_OS_IPHONE)
48- [self postNotificationName: aName object: aSender userInfo: userInfo];
61+ [[NSDistributedNotificationCenter defaultCenter ]
62+ postNotificationName: aName
63+ object: aSender
64+ userInfo: userInfo
65+ deliverImmediately: deliverImmediately];
66+ #else
67+ [[NSNotificationCenter defaultCenter ]
68+ postNotificationName: aName
69+ object: aSender
70+ userInfo: userInfo];
4971#endif
5072}
5173
0 commit comments