当我的输入法在MacOS上发生变化时,我希望得到通知,所以我有以下代码:
#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
void notificationCallback (CFNotificationCenterRef center, void * observer, CFStringRef name, const void * object, CFDictionaryRef userInfo) {
fprintf(stdout, "%s\n", "abc");
}
int main(int argc, const char * argv[]) {
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterAddObserver(center, NULL, notificationCallback,
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
while(1) {
}
}并使用以下命令进行编译
/usr/bin/clang -framework foundation -framework carbon -o im-select im-select.m它可以编译,但在运行im-select并更改输入方法后,我永远得不到反馈。
这些代码在应用程序中工作得很好,我只是不知道为什么它不能在命令行中工作。
发布于 2018-04-03 12:52:44
https://stackoverflow.com/questions/49617898
复制相似问题