gpt4 book ai didi

objective-c - NSWorkspaceDidTerminateApplicationNotification 崩溃

转载 作者:行者123 更新时间:2023-12-03 17:25:42 26 4
gpt4 key购买 nike

所以我的一些用户遇到了崩溃,我认为我已经将其追踪到了 NSWorkspaceDidTerminateApplicationNotification,我根本无法重现崩溃,所以我不知道该去哪里?

这是生成的崩溃日志,也许我遗漏了一些明显的东西:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010
Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: invalidate


Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff816f211c objc_msgSend + 40
1 com.apple.Foundation 0x00007fff87ef58ea _nsnote_callback + 167
2 com.apple.CoreFoundation 0x00007fff869b3000 __CFXNotificationPost + 1008
3 com.apple.CoreFoundation 0x00007fff8699f578 _CFXNotificationPostNotification + 200
4 com.apple.Foundation 0x00007fff87eec84e -[NSNotificationCenter postNotificationName:object:userInfo:] + 101
5 com.apple.AppKit 0x00007fff878efb58 applicationStatusSubsystemCallback + 593
6 com.apple.LaunchServices 0x00007fff83523e6c LSScheduleNotificationReceiveMessageCallbackFunc(__CFMachPort*, void*, long, void*) + 184
7 com.apple.CoreFoundation 0x00007fff869cf68e __CFMachPortPerform + 366
8 com.apple.CoreFoundation 0x00007fff869a76e1 __CFRunLoopRun + 5201
9 com.apple.CoreFoundation 0x00007fff869a5dbf CFRunLoopRunSpecific + 575
10 com.apple.HIToolbox 0x00007fff80ef07ee RunCurrentEventLoopInMode + 333
11 com.apple.HIToolbox 0x00007fff80ef05f3 ReceiveNextEventCommon + 310
12 com.apple.HIToolbox 0x00007fff80ef04ac BlockUntilNextEventMatchingListInMode + 59
13 com.apple.AppKit 0x00007fff87232e64 _DPSNextEvent + 718
14 com.apple.AppKit 0x00007fff872327a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
15 com.apple.AppKit 0x00007fff871f848b -[NSApplication run] + 395
16 com.apple.AppKit 0x00007fff871f11a8 NSApplicationMain + 364

这是相关代码:

NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
[center addObserver:self selector:@selector(appTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];

- (void)appTerminated:(NSNotification *)note
{
NSString *app = [NSString stringWithFormat:@"%@", [[note userInfo] objectForKey:@"NSApplicationName"]];

if ([app isEqualToString:Somestring])
{
//do something here
}
}
}

如果有人能给我一些关于去哪里寻找的指示,我将永远感激不已,我已经好几天了……

最佳答案

看起来您的窗口 Controller 正在被释放,同时仍在通知中心注册。您需要确保在释放之前窗口 Controller 未注册。否则,通知中心将尝试向已释放的对象发布通知,这可能会触发 EXC_BAD_ACCESS 异常。

例如,在您的窗口 Controller 实现中:

- (void)dealloc {
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[super dealloc];
}

这将针对在通知中心注册的每个通知注销窗口 Controller 。

关于objective-c - NSWorkspaceDidTerminateApplicationNotification 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5696718/

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