Listening to all CFNotifications?
I'm writing a little test program where I can look at all the notifications being posted as various actions occur on an iOS devices. Unfortunately, I'm running into a problem where I get an EXC_BAD_ACCESS error when I even try to add an observer to the Darwin notification center. The relevant code is below:
void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSNotification* n = [NSNotification notificationWithName:name object:object userInfo:userInfo];
objc_msgSend(gSelf, sel_getUid(@"note:"), n);
return;
}
- (void)viewDidLoad {
[super viewDidLoad];
gSelf = self;
notifications = [[NSMutableArray alloc] initWithCapacity:10];
self.title = @"Notification Log";
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
callback, // callback
NULL, // name
NULL, // object
CFNotificationSuspensionBehaviorHold
);
}
-(void)note:(NSNotification *)notification{
@synchronized(self){
[notifications addObject:notification];
[self.tableView reloadData开发者_如何学C];
}
}
From CFNotificationCenter.h: (Look for the definition of CFNotificationCenterGetDarwinNotifyCenter
.) or the CFNotificationCenter reference
CFNotificationCenterAddObserver(): the 'name' argument may not be NULL (for this center).
精彩评论