gpt4 book ai didi

iphone - 监听所有 CFNotifications?

转载 作者:行者123 更新时间:2023-12-03 19:42:29 36 4
gpt4 key购买 nike

我正在编写一个小测试程序,可以在其中查看 iOS 设备上发生各种操作时发布的所有通知。不幸的是,我遇到了一个问题,当我尝试向 Darwin 通知中心添加观察者时,我收到 EXC_BAD_ACCESS 错误。相关代码如下:

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];
}
}

最佳答案

来自 CFNotificationCenter.h:(查找 CFNotificationCenterGetDarwinNotifyCenter 的定义。)或 the CFNotificationCenter reference

CFNotificationCenterAddObserver(): the 'name' argument may not be NULL (for this center).

关于iphone - 监听所有 CFNotifications?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3964916/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com