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