Receiver exampleA distributed notification center delivers notifications between applications. A notification object used with a distributed notification center must always be a CFString object and the notification dictionary must contain only property list values.
Code: Select all
; >>> Constants and imports <<<
#CFNotificationSuspensionBehaviorDeliverImmediately = 4
ImportC "-framework CoreFoundation"
CFNotificationCenterAddObserver(center, observer, callBack, name, object, suspensionBehavior)
CFNotificationCenterGetDistributedCenter()
CFNotificationCenterPostNotification(center, name, object, userInfo, deliverImmediately)
CFRelease(cf)
CFStringCreateWithCString(alloc, cStr.p-utf8, encoding = $8000100)
EndImport
; >>> Receiver code <<<
ProcedureC Callback(center, observer, name, object, userInfo)
Protected s.s
If name And IsGadget(0)
s = PeekS(CocoaMessage(0, name, "UTF8String"), -1, #PB_UTF8)
AddGadgetItem(0, -1, s)
EndIf
EndProcedure
distributedCenter = CFNotificationCenterGetDistributedCenter()
object = CFStringCreateWithCString(0, "notification.myApp")
CFNotificationCenterAddObserver(distributedCenter, #Null, @Callback(), #Null, object,
#CFNotificationSuspensionBehaviorDeliverImmediately)
OpenWindow(0, 0, 0, 320, 170, "Receiver", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 300, 150)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Code: Select all
; >>> Constants and imports <<<
#CFNotificationSuspensionBehaviorDeliverImmediately = 4
ImportC "-framework CoreFoundation"
CFNotificationCenterAddObserver(center, observer, callBack, name, object, suspensionBehavior)
CFNotificationCenterGetDistributedCenter()
CFNotificationCenterPostNotification(center, name, object, userInfo, deliverImmediately)
CFRelease(cf)
CFStringCreateWithCString(alloc, cStr.p-utf8, encoding = $8000100)
EndImport
; >>> Sender code <<<
distributedCenter = CFNotificationCenterGetDistributedCenter()
object = CFStringCreateWithCString(0, "notification.myApp")
name = CFStringCreateWithCString(0, "filename.txt")
CFNotificationCenterPostNotification(distributedCenter, name, object, #Null, #True)
CFRelease(name)