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 /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
189 /// > as shown on this page, or you can call it as an asynchronous method that has the
190 /// > following declaration:
191 /// >
192 /// > ```swift
193 /// > optional func didReceive(_ response: UNNotificationResponse) async -> UNNotificationContentExtensionResponseOption
194 /// > ```
195 /// >
196 /// > For information about concurrency and asynchronous code in Swift, see
197 /// <doc
198 /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
199 ///
200 /// Implement this method when you want your view controller to handle actions
201 /// selected by the user. Use your implementation to perform the associated task
202 /// and then execute the `completion` block. If you implement this method, you
203 /// must handle all actions defined in all categories managed by your
204 /// Notification Content app extension. If you don't implement this method, the
205 /// system notifies your app when the user selects an action.
206 ///
207 /// - Parameters:
208 /// - response: The response object that identifies the user-selected action.
209 /// Use this object to get information about the notification and the user’s
210 /// response.
211 /// - completion: The block to execute when you are finished performing the
212 /// action. You must call this block at some point during your implementation.
213 /// The block has no return value and takes the following parameter:
214 /// - term `dismiss`: The response you want to take for the notification. For a list of
215 /// possible options, see
216 /// ``UserNotificationsUI/UNNotificationContentExtensionResponseOption``.
217 #[optional]
218 #[unsafe(method(didReceiveNotificationResponse:completionHandler:))]
219 #[unsafe(method_family = none)]
220 unsafe fn didReceiveNotificationResponse_completionHandler(
221 &self,
222 response: &UNNotificationResponse,
223 completion: &block2::DynBlock<dyn Fn(UNNotificationContentExtensionResponseOption)>,
224 );
225
226 /// The type of media button type to display.
227 ///
228 /// Implement this property when you want the system to display a media playback
229 /// button in your notification interface. Return an appropriate constant
230 /// indicating the type of button you want. If you don't implement this
231 /// property, the system behaves as if you set the value to
232 /// ``UNNotificationContentExtensionMediaPlayPauseButtonType/UNNotificationContentExtensionMediaPlayPauseButtonTypeNone``.
233 #[optional]
234 #[unsafe(method(mediaPlayPauseButtonType))]
235 #[unsafe(method_family = none)]
236 unsafe fn mediaPlayPauseButtonType(
237 &self,
238 ) -> UNNotificationContentExtensionMediaPlayPauseButtonType;
239
240 #[cfg(feature = "objc2-core-foundation")]
241 /// The frame rectangle to use for displaying a media playback button.
242 ///
243 /// If you support the playback of media directly from your notification
244 /// interface, implement this property and use it to return a nonempty rectangle
245 /// specified in the coordinate system of your view controller’s view. The
246 /// system draws a button in the provided rectangle that lets the user play and
247 /// pause your media content. The system handles the drawing of the button for
248 /// you and calls the ``UNNotificationContentExtension/mediaPlay`` and
249 /// ``UNNotificationContentExtension/mediaPause`` methods in response to user
250 /// interactions. You can place this button anywhere in your view controller’s
251 /// view.
252 ///
253 /// If you don't implement this property, the system doesn't draw a media
254 /// playback button.
255 #[optional]
256 #[unsafe(method(mediaPlayPauseButtonFrame))]
257 #[unsafe(method_family = none)]
258 unsafe fn mediaPlayPauseButtonFrame(&self) -> CGRect;
259
260 #[cfg(feature = "objc2-app-kit")]
261 #[cfg(target_os = "macos")]
262 /// The tint color for the media playback button.
263 ///
264 /// If you implement the
265 /// ``UNNotificationContentExtension/mediaPlayPauseButtonFrame`` property, you
266 /// can also implement this property and use it to specify the tint color to
267 /// apply to the button. If you don't implement this property, the system uses a
268 /// default color for the tint color.
269 #[optional]
270 #[unsafe(method(mediaPlayPauseButtonTintColor))]
271 #[unsafe(method_family = none)]
272 unsafe fn mediaPlayPauseButtonTintColor(&self) -> Retained<NSColor>;
273
274 /// Tells you to begin 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 /// begin playback of your media. Use your implementation of this method to
280 /// initiate playback.
281 #[optional]
282 #[unsafe(method(mediaPlay))]
283 #[unsafe(method_family = none)]
284 unsafe fn mediaPlay(&self);
285
286 /// Tells you to pause playback of your media content.
287 ///
288 /// Don't call this method yourself. If you implement the
289 /// ``UNNotificationContentExtension/mediaPlayPauseButtonFrame`` property in
290 /// your view controller, the system calls this method when the user wants to
291 /// stop playback of your media. Use your implementation of this method to pause
292 /// playback at the current location.
293 #[optional]
294 #[unsafe(method(mediaPause))]
295 #[unsafe(method_family = none)]
296 unsafe fn mediaPause(&self);
297 }
298);
299
300mod private_NSExtensionContextUNNotificationContentExtension {
301 pub trait Sealed {}
302}
303
304/// Category "UNNotificationContentExtension" on [`NSExtensionContext`].
305#[doc(alias = "UNNotificationContentExtension")]
306pub unsafe trait NSExtensionContextUNNotificationContentExtension:
307 ClassType + Sized + private_NSExtensionContextUNNotificationContentExtension::Sealed
308{
309 extern_methods!(
310 #[cfg(feature = "objc2-user-notifications")]
311 #[unsafe(method(notificationActions))]
312 #[unsafe(method_family = none)]
313 unsafe fn notificationActions(&self) -> Retained<NSArray<UNNotificationAction>>;
314
315 #[cfg(feature = "objc2-user-notifications")]
316 /// Setter for [`notificationActions`][Self::notificationActions].
317 #[unsafe(method(setNotificationActions:))]
318 #[unsafe(method_family = none)]
319 unsafe fn setNotificationActions(
320 &self,
321 notification_actions: &NSArray<UNNotificationAction>,
322 );
323
324 #[unsafe(method(performNotificationDefaultAction))]
325 #[unsafe(method_family = none)]
326 unsafe fn performNotificationDefaultAction(&self);
327
328 #[unsafe(method(dismissNotificationContentExtension))]
329 #[unsafe(method_family = none)]
330 unsafe fn dismissNotificationContentExtension(&self);
331
332 #[unsafe(method(mediaPlayingStarted))]
333 #[unsafe(method_family = none)]
334 unsafe fn mediaPlayingStarted(&self);
335
336 #[unsafe(method(mediaPlayingPaused))]
337 #[unsafe(method_family = none)]
338 unsafe fn mediaPlayingPaused(&self);
339 );
340}
341
342impl private_NSExtensionContextUNNotificationContentExtension::Sealed for NSExtensionContext {}
343unsafe impl NSExtensionContextUNNotificationContentExtension for NSExtensionContext {}