objc2_user_notifications_ui/generated/UNNotificationContentExtension.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-foundation")]
10use objc2_core_foundation::*;
11use objc2_foundation::*;
12#[cfg(feature = "objc2-user-notifications")]
13use objc2_user_notifications::*;
14
15use crate::*;
16
17/// Constants indicating the type of media button to display.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextensionmediaplaypausebuttontype?language=objc)
20// NS_ENUM
21#[repr(transparent)]
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
23pub struct UNNotificationContentExtensionMediaPlayPauseButtonType(pub NSUInteger);
24impl UNNotificationContentExtensionMediaPlayPauseButtonType {
25 /// No media button.
26 ///
27 /// Specify this option when you don't want a media button. This is the
28 /// default option.
29 #[doc(alias = "UNNotificationContentExtensionMediaPlayPauseButtonTypeNone")]
30 pub const None: Self = Self(0);
31 /// A standard play/pause button.
32 ///
33 /// This button is always visible. When tapped, its appearance changes
34 /// between the play and pause icons and triggers the appropriate play and
35 /// pause actions.
36 #[doc(alias = "UNNotificationContentExtensionMediaPlayPauseButtonTypeDefault")]
37 pub const Default: Self = Self(1);
38 /// A partially transparent play/pause button that is layered on top of your
39 /// media content.
40 ///
41 /// This button draws a play icon over the content initially. When playback
42 /// begins, the button disappears. Tapping the content again pauses playback and
43 /// displays the play button again.
44 #[doc(alias = "UNNotificationContentExtensionMediaPlayPauseButtonTypeOverlay")]
45 pub const Overlay: Self = Self(2);
46}
47
48unsafe impl Encode for UNNotificationContentExtensionMediaPlayPauseButtonType {
49 const ENCODING: Encoding = NSUInteger::ENCODING;
50}
51
52unsafe impl RefEncode for UNNotificationContentExtensionMediaPlayPauseButtonType {
53 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
54}
55
56/// Constants indicating the preferred response to a notification.
57///
58/// See also [Apple's documentation](https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextensionresponseoption?language=objc)
59// NS_ENUM
60#[repr(transparent)]
61#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
62pub struct UNNotificationContentExtensionResponseOption(pub NSUInteger);
63impl UNNotificationContentExtensionResponseOption {
64 /// Don't dismiss the notification interface.
65 ///
66 /// The content extension handles the selected action.
67 #[doc(alias = "UNNotificationContentExtensionResponseOptionDoNotDismiss")]
68 pub const DoNotDismiss: Self = Self(0);
69 /// Dismiss the notification interface.
70 ///
71 /// The content extension handles the selected action.
72 #[doc(alias = "UNNotificationContentExtensionResponseOptionDismiss")]
73 pub const Dismiss: Self = Self(1);
74 /// Dismiss the notification interface and forward the notification to the app.
75 ///
76 /// Choose this option when you want the app to respond to the action or handle
77 /// it.
78 #[doc(alias = "UNNotificationContentExtensionResponseOptionDismissAndForwardAction")]
79 pub const DismissAndForwardAction: Self = Self(2);
80}
81
82unsafe impl Encode for UNNotificationContentExtensionResponseOption {
83 const ENCODING: Encoding = NSUInteger::ENCODING;
84}
85
86unsafe impl RefEncode for UNNotificationContentExtensionResponseOption {
87 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
88}
89
90extern_protocol!(
91 /// An object that presents a custom interface for a delivered local or remote
92 /// notification.
93 ///
94 /// The `UNNotificationContentExtension` protocol provides the entry point for
95 /// a notification content app extension, which displays a custom interface for
96 /// your app’s notifications. You adopt this protocol in the custom
97 /// <doc
98 /// ://com.apple.documentation/documentation/uikit/uiviewcontroller>
99 /// subclass that you use to present your interface. You create this type of
100 /// extension to improve the way your notifications are presented, possibly by
101 /// adding custom colors and branding, or by incorporating media and other
102 /// dynamic content into your notification interface.
103 ///
104 /// To define a notification content app extension, add a notification content
105 /// extension target to the Xcode project containing your app. The default Xcode
106 /// template contains a source file and storyboard for your view controller. The
107 /// `Info.plist` file of the extension comes mostly configured. Specifically,
108 /// the `NSExtensionPointIdentifier` key is set to the value
109 /// `com.apple.usernotifications.content-extension`, and the
110 /// `NSExtensionMainStoryboard` key is set to the name of the project’s
111 /// storyboard file. However, the `NSExtensionAttribute` key contains a
112 /// dictionary of additional keys and values, which are listed in the following table.
113 ///
114 /// | Key | Value |
115 /// | --- | ----- |
116 /// | `UNNotificationExtensionCategory` (Required) | A string or an array of strings. Each string contains the identifier of a category declared by the app using the
117 /// <doc
118 /// ://com.apple.documentation/documentation/usernotifications/unnotificationcategory> class. |
119 /// | `UNNotificationExtensionInitialContentSizeRatio` (Required) | A floating-point number that represents the initial size of your view controller’s view expressed as a ratio of its height to its width. The system uses this value to set the initial size of the view controller while your extension is loading. For example, a value of 0.5 results in a view controller whose height is half its width. You can change the size of your view controller after your extension loads. |
120 /// | `UNNotificationExtensionDefaultContentHidden` | A Boolean. When set to
121 /// <doc
122 /// ://com.apple.documentation/documentation/objectivec/yes>, the system displays only your custom view controller in the notification interface. When set to
123 /// <doc
124 /// ://com.apple.documentation/documentation/objectivec/no>, the system displays the default notification content in addition to your view controller’s content. Custom action buttons and the Dismiss button are always displayed, regardless of this setting. If you don't specify this key, the default value is set to
125 /// <doc
126 /// ://com.apple.documentation/documentation/objectivec/no>. |
127 /// | `UNNotificationExtensionOverridesDefaultTitle` | A Boolean. When set to
128 /// <doc
129 /// ://com.apple.documentation/documentation/objectivec/yes>, the system uses the
130 /// <doc
131 /// ://com.apple.documentation/documentation/uikit/uiviewcontroller/1621364-title> property of your view controller as the title of the notification. When set to
132 /// <doc
133 /// ://com.apple.documentation/documentation/objectivec/no>, the system sets the notification's title to the name of your app. If you don't specify this key, the default value is set to
134 /// <doc
135 /// ://com.apple.documentation/documentation/objectivec/no>. |
136 ///
137 /// If the notification category includes custom actions, the system
138 /// automatically adds action buttons to your notification interface; don't
139 /// create those buttons yourself. If your view controller implements the
140 /// optional
141 /// ``UNNotificationContentExtension/didReceiveNotificationResponse:completionHandler:``
142 /// method, the system calls that method to respond to any selected actions. If
143 /// your view controller doesn't implement that method, the system delivers the
144 /// selected action to your app for handling.
145 ///
146 /// The system prevents the delivery of touch events to your view controller
147 /// while it is onscreen. Do not install gesture recognizers or rely on touch
148 /// events in your interface.
149 ///
150 /// For information about how to implement your notification content app
151 /// extension, see
152 /// <doc
153 /// :customizing-the-appearance-of-notifications>.
154 ///
155 /// See also [Apple's documentation](https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension?language=objc)
156 pub unsafe trait UNNotificationContentExtension: NSObjectProtocol {
157 #[cfg(feature = "objc2-user-notifications")]
158 /// Delivers a new notification to your notification content app extension.
159 ///
160 /// In your implementation of this method, use the contents of `notification` to
161 /// configure your view controller. This method may be called multiple times
162 /// while your view controller is visible. Specifically, it is called again when
163 /// a new notification arrives whose
164 /// <doc
165 /// ://com.apple.documentation/documentation/usernotifications/unnotificationcontent/1649860-threadidentifier>
166 /// value matches the thread identifier of the notification already being
167 /// displayed. The method is called on the main thread of your notification
168 /// content app extension.
169 ///
170 /// If you want to accommodate new content in your interface, you can change the
171 /// height of your view controller's view. Change only the height; width values
172 /// are ignored. You can then add subviews to fill the additional space with
173 /// your content.
174 ///
175 /// - Parameters:
176 /// - notification: The notification that arrived.
177 #[unsafe(method(didReceiveNotification:))]
178 #[unsafe(method_family = none)]
179 unsafe fn didReceiveNotification(
180 &self,
181 notification: &UNNotification,
182 mtm: MainThreadMarker,
183 );
184
185 #[cfg(all(feature = "block2", feature = "objc2-user-notifications"))]
186 /// Handles a notification action selected by the user.
187 ///
188 /// Implement this method when you want your view controller to handle actions
189 /// selected by the user. Use your implementation to perform the associated task
190 /// and then execute the `completion` block. If you implement this method, you
191 /// must handle all actions defined in all categories managed by your
192 /// Notification Content app extension. If you don't implement this method, the
193 /// system notifies your app when the user selects an action.
194 ///
195 /// - Parameters:
196 /// - response: The response object that identifies the user-selected action.
197 /// Use this object to get information about the notification and the user’s
198 /// response.
199 /// - completion: The block to execute when you are finished performing the
200 /// action. You must call this block at some point during your implementation.
201 /// The block has no return value and takes the following parameter:
202 /// - term `dismiss`: The response you want to take for the notification. For a list of
203 /// possible options, see
204 /// ``UserNotificationsUI/UNNotificationContentExtensionResponseOption``.
205 #[optional]
206 #[unsafe(method(didReceiveNotificationResponse:completionHandler:))]
207 #[unsafe(method_family = none)]
208 unsafe fn didReceiveNotificationResponse_completionHandler(
209 &self,
210 response: &UNNotificationResponse,
211 completion: &block2::DynBlock<dyn Fn(UNNotificationContentExtensionResponseOption)>,
212 );
213
214 /// The type of media button type to display.
215 ///
216 /// Implement this property when you want the system to display a media playback
217 /// button in your notification interface. Return an appropriate constant
218 /// indicating the type of button you want. If you don't implement this
219 /// property, the system behaves as if you set the value to
220 /// ``UNNotificationContentExtensionMediaPlayPauseButtonType/UNNotificationContentExtensionMediaPlayPauseButtonTypeNone``.
221 #[optional]
222 #[unsafe(method(mediaPlayPauseButtonType))]
223 #[unsafe(method_family = none)]
224 unsafe fn mediaPlayPauseButtonType(
225 &self,
226 ) -> UNNotificationContentExtensionMediaPlayPauseButtonType;
227
228 #[cfg(feature = "objc2-core-foundation")]
229 /// The frame rectangle to use for displaying a media playback button.
230 ///
231 /// If you support the playback of media directly from your notification
232 /// interface, implement this property and use it to return a nonempty rectangle
233 /// specified in the coordinate system of your view controller’s view. The
234 /// system draws a button in the provided rectangle that lets the user play and
235 /// pause your media content. The system handles the drawing of the button for
236 /// you and calls the ``UNNotificationContentExtension/mediaPlay`` and
237 /// ``UNNotificationContentExtension/mediaPause`` methods in response to user
238 /// interactions. You can place this button anywhere in your view controller’s
239 /// view.
240 ///
241 /// If you don't implement this property, the system doesn't draw a media
242 /// playback button.
243 #[optional]
244 #[unsafe(method(mediaPlayPauseButtonFrame))]
245 #[unsafe(method_family = none)]
246 unsafe fn mediaPlayPauseButtonFrame(&self) -> CGRect;
247
248 #[cfg(feature = "objc2-app-kit")]
249 #[cfg(target_os = "macos")]
250 /// The tint color for the media playback button.
251 ///
252 /// If you implement the
253 /// ``UNNotificationContentExtension/mediaPlayPauseButtonFrame`` property, you
254 /// can also implement this property and use it to specify the tint color to
255 /// apply to the button. If you don't implement this property, the system uses a
256 /// default color for the tint color.
257 #[optional]
258 #[unsafe(method(mediaPlayPauseButtonTintColor))]
259 #[unsafe(method_family = none)]
260 unsafe fn mediaPlayPauseButtonTintColor(&self) -> Retained<NSColor>;
261
262 /// Tells you to begin playback of your media content.
263 ///
264 /// Don't call this method yourself. If you implement the
265 /// ``UNNotificationContentExtension/mediaPlayPauseButtonFrame`` property in
266 /// your view controller, the system calls this method when the user wants to
267 /// begin playback of your media. Use your implementation of this method to
268 /// initiate playback.
269 #[optional]
270 #[unsafe(method(mediaPlay))]
271 #[unsafe(method_family = none)]
272 unsafe fn mediaPlay(&self);
273
274 /// Tells you to pause playback of your media content.
275 ///
276 /// Don't call this method yourself. If you implement the
277 /// ``UNNotificationContentExtension/mediaPlayPauseButtonFrame`` property in
278 /// your view controller, the system calls this method when the user wants to
279 /// stop playback of your media. Use your implementation of this method to pause
280 /// playback at the current location.
281 #[optional]
282 #[unsafe(method(mediaPause))]
283 #[unsafe(method_family = none)]
284 unsafe fn mediaPause(&self);
285 }
286);
287
288mod private_NSExtensionContextUNNotificationContentExtension {
289 pub trait Sealed {}
290}
291
292/// Category "UNNotificationContentExtension" on [`NSExtensionContext`].
293#[doc(alias = "UNNotificationContentExtension")]
294pub unsafe trait NSExtensionContextUNNotificationContentExtension:
295 ClassType + Sized + private_NSExtensionContextUNNotificationContentExtension::Sealed
296{
297 extern_methods!(
298 #[cfg(feature = "objc2-user-notifications")]
299 #[unsafe(method(notificationActions))]
300 #[unsafe(method_family = none)]
301 unsafe fn notificationActions(&self) -> Retained<NSArray<UNNotificationAction>>;
302
303 #[cfg(feature = "objc2-user-notifications")]
304 /// Setter for [`notificationActions`][Self::notificationActions].
305 ///
306 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
307 #[unsafe(method(setNotificationActions:))]
308 #[unsafe(method_family = none)]
309 unsafe fn setNotificationActions(
310 &self,
311 notification_actions: &NSArray<UNNotificationAction>,
312 );
313
314 #[unsafe(method(performNotificationDefaultAction))]
315 #[unsafe(method_family = none)]
316 unsafe fn performNotificationDefaultAction(&self);
317
318 #[unsafe(method(dismissNotificationContentExtension))]
319 #[unsafe(method_family = none)]
320 unsafe fn dismissNotificationContentExtension(&self);
321
322 #[unsafe(method(mediaPlayingStarted))]
323 #[unsafe(method_family = none)]
324 unsafe fn mediaPlayingStarted(&self);
325
326 #[unsafe(method(mediaPlayingPaused))]
327 #[unsafe(method_family = none)]
328 unsafe fn mediaPlayingPaused(&self);
329 );
330}
331
332impl private_NSExtensionContextUNNotificationContentExtension::Sealed for NSExtensionContext {}
333unsafe impl NSExtensionContextUNNotificationContentExtension for NSExtensionContext {}