在一些开发人员同事的帮助下,我发现了问题所在。的签名
SCDynamicStoreSetNotificationKeys
功能如下:
Boolean SCDynamicStoreSetNotificationKeys (SCDynamicStoreRef store,
CFArrayRef __nullable keys,
CFArrayRef __nullable patterns
)
这意味着我必须将模式与作为树根的键分开设置,在树根下模式匹配将发生。这是我的修改版
主m
:
int main(int argc, const char * argv[]) {
NSArray *SCMonitoringInterfaceKeys = @[@"State:/Network/Interface"];
NSArray *patterns = @[@"en\\d*/IPv4"];
@autoreleasepool {
SCDynamicStoreRef dsr = SCDynamicStoreCreate(NULL, CFSTR("network_interface_detector"), &dynamicStoreCallback, NULL);
SCDynamicStoreSetNotificationKeys(dsr, CFBridgingRetain(SCMonitoringInterfaceKeys), CFBridgingRetain(patterns));
CFRunLoopAddSource(CFRunLoopGetCurrent(), SCDynamicStoreCreateRunLoopSource(NULL, dsr, 0), kCFRunLoopDefaultMode);
NSLog(@"Starting RunLoop...");
while([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
}
return 0;
}
我已经包括了解决方案
into the solved branch of the repo
.