CFUserNotification object presents a simple dialog on the screen and optionally receives feedback from the user. The contents of the dialog can include a header, a message, an icon, text fields, a pop-up button, radio buttons or checkboxes, and up to three ordinary buttons. Use
CFUserNotification in processes that do not otherwise have user interfaces, but may need occasional interaction with the user.
You create a user notification with the
CFUserNotificationCreate(_:_:_:_:_:) function. You pass in a dictionary whose keys describe the items to place into the dialog. (See Dialog Description Keys for the list of keys.) A set of flags passed to the function determines, among other things, whether secure text fields are used (such as for password fields), whether radio buttons or checkboxes are used, and which of these buttons are checked by default. You can also specify a timeout for the dialog, in which case the dialog cancels itself if the user does not respond in the allotted time period.
A user notification displays its dialog as soon as it is created. If any reply is required, it may be awaited in one of two ways: either synchronously, using
CFUserNotificationReceiveResponse(_:_:_:), or asynchronously, using a run loop source created with
CFUserNotificationReceiveResponse(_:_:_:) has a timeout parameter that determines how long it will block (zero meaning indefinitely) and it may be called as many times as necessary until a response arrives. If a user notification has not yet received a response, it may be updated with new information or it may be cancelled. User notifications may not be reused.
CFUserNotification provides two convenience functions,
CFUserNotificationDisplayAlert(_:_:_:_:_:_:_:_:_:_:_:), to display very basic dialogs that either require no response from the user or require only a single button to be pressed, respectively.