cfnotification

Using CFNotificationCallback in Swift, or, @convention(c) blocks in Swift

梦想的初衷 提交于 2019-12-29 08:18:10
问题 I am trying to listen to CoreTelephony notifications using the (now private) CTTelephonyCenterAddObserver C function and CFNotificationCallback callback blocks. My bridging header (to extern the private C functions): #include <CoreFoundation/CoreFoundation.h> #if __cplusplus extern "C" { #endif #pragma mark - API /* This API is a mimic of CFNotificationCenter. */ CFNotificationCenterRef CTTelephonyCenterGetDefault(); void CTTelephonyCenterAddObserver(CFNotificationCenterRef center, const void

How can I send a userInfo dict using CFNotificationCenterGetDarwinNotifyCenter()

风流意气都作罢 提交于 2019-12-10 20:05:48
问题 I need to send an object using CFNotificationCenterGetDarwinNotifyCenter() however, I'm noticing that whenever I send a notification using const void *tkeys[1] = { @"testKey" }; const void *tvalues[1] = { @"testValue" }; CFDictionaryRef userInfo = CFDictionaryCreate(NULL, tkeys, tvalues, 1, NULL, NULL); CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("foo"), object, userInfo, true); then I find that in the observer callback, the userInfo dict is NULL.

Using CFNotificationCallback in Swift, or, @convention(c) blocks in Swift

▼魔方 西西 提交于 2019-11-29 12:41:20
I am trying to listen to CoreTelephony notifications using the (now private) CTTelephonyCenterAddObserver C function and CFNotificationCallback callback blocks. My bridging header (to extern the private C functions): #include <CoreFoundation/CoreFoundation.h> #if __cplusplus extern "C" { #endif #pragma mark - API /* This API is a mimic of CFNotificationCenter. */ CFNotificationCenterRef CTTelephonyCenterGetDefault(); void CTTelephonyCenterAddObserver(CFNotificationCenterRef center, const void *observer, CFNotificationCallback callBack, CFStringRef name, const void *object,