objc2_user_notifications/generated/
UNUserNotificationCenter.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unauthorizationoptions?language=objc)
11// NS_OPTIONS
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct UNAuthorizationOptions(pub NSUInteger);
15bitflags::bitflags! {
16    impl UNAuthorizationOptions: NSUInteger {
17        #[doc(alias = "UNAuthorizationOptionBadge")]
18        const Badge = 1<<0;
19        #[doc(alias = "UNAuthorizationOptionSound")]
20        const Sound = 1<<1;
21        #[doc(alias = "UNAuthorizationOptionAlert")]
22        const Alert = 1<<2;
23        #[doc(alias = "UNAuthorizationOptionCarPlay")]
24        const CarPlay = 1<<3;
25        #[doc(alias = "UNAuthorizationOptionCriticalAlert")]
26        const CriticalAlert = 1<<4;
27        #[doc(alias = "UNAuthorizationOptionProvidesAppNotificationSettings")]
28        const ProvidesAppNotificationSettings = 1<<5;
29        #[doc(alias = "UNAuthorizationOptionProvisional")]
30        const Provisional = 1<<6;
31#[deprecated = "Announcement authorization is always included"]
32        #[doc(alias = "UNAuthorizationOptionAnnouncement")]
33        const Announcement = 1<<7;
34#[deprecated = "Use time-sensitive entitlement"]
35        #[doc(alias = "UNAuthorizationOptionTimeSensitive")]
36        const TimeSensitive = 1<<8;
37    }
38}
39
40unsafe impl Encode for UNAuthorizationOptions {
41    const ENCODING: Encoding = NSUInteger::ENCODING;
42}
43
44unsafe impl RefEncode for UNAuthorizationOptions {
45    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
46}
47
48/// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unauthorizationoptionnone?language=objc)
49pub static UNAuthorizationOptionNone: UNAuthorizationOptions = UNAuthorizationOptions(0);
50
51extern_class!(
52    /// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unusernotificationcenter?language=objc)
53    #[unsafe(super(NSObject))]
54    #[derive(Debug, PartialEq, Eq, Hash)]
55    pub struct UNUserNotificationCenter;
56);
57
58unsafe impl NSObjectProtocol for UNUserNotificationCenter {}
59
60impl UNUserNotificationCenter {
61    extern_methods!(
62        #[unsafe(method(delegate))]
63        #[unsafe(method_family = none)]
64        pub unsafe fn delegate(
65            &self,
66        ) -> Option<Retained<ProtocolObject<dyn UNUserNotificationCenterDelegate>>>;
67
68        /// This is a [weak property][objc2::topics::weak_property].
69        /// Setter for [`delegate`][Self::delegate].
70        #[unsafe(method(setDelegate:))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn setDelegate(
73            &self,
74            delegate: Option<&ProtocolObject<dyn UNUserNotificationCenterDelegate>>,
75        );
76
77        #[unsafe(method(supportsContentExtensions))]
78        #[unsafe(method_family = none)]
79        pub unsafe fn supportsContentExtensions(&self) -> bool;
80
81        #[unsafe(method(currentNotificationCenter))]
82        #[unsafe(method_family = none)]
83        pub unsafe fn currentNotificationCenter() -> Retained<UNUserNotificationCenter>;
84
85        #[unsafe(method(init))]
86        #[unsafe(method_family = init)]
87        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
88
89        #[cfg(feature = "block2")]
90        #[unsafe(method(requestAuthorizationWithOptions:completionHandler:))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn requestAuthorizationWithOptions_completionHandler(
93            &self,
94            options: UNAuthorizationOptions,
95            completion_handler: &block2::Block<dyn Fn(Bool, *mut NSError)>,
96        );
97
98        #[cfg(feature = "UNNotificationCategory")]
99        #[unsafe(method(setNotificationCategories:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn setNotificationCategories(&self, categories: &NSSet<UNNotificationCategory>);
102
103        #[cfg(all(feature = "UNNotificationCategory", feature = "block2"))]
104        #[unsafe(method(getNotificationCategoriesWithCompletionHandler:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn getNotificationCategoriesWithCompletionHandler(
107            &self,
108            completion_handler: &block2::Block<dyn Fn(NonNull<NSSet<UNNotificationCategory>>)>,
109        );
110
111        #[cfg(all(feature = "UNNotificationSettings", feature = "block2"))]
112        #[unsafe(method(getNotificationSettingsWithCompletionHandler:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn getNotificationSettingsWithCompletionHandler(
115            &self,
116            completion_handler: &block2::Block<dyn Fn(NonNull<UNNotificationSettings>)>,
117        );
118
119        #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
120        #[unsafe(method(addNotificationRequest:withCompletionHandler:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn addNotificationRequest_withCompletionHandler(
123            &self,
124            request: &UNNotificationRequest,
125            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
126        );
127
128        #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
129        #[unsafe(method(getPendingNotificationRequestsWithCompletionHandler:))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn getPendingNotificationRequestsWithCompletionHandler(
132            &self,
133            completion_handler: &block2::Block<dyn Fn(NonNull<NSArray<UNNotificationRequest>>)>,
134        );
135
136        #[unsafe(method(removePendingNotificationRequestsWithIdentifiers:))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn removePendingNotificationRequestsWithIdentifiers(
139            &self,
140            identifiers: &NSArray<NSString>,
141        );
142
143        #[unsafe(method(removeAllPendingNotificationRequests))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn removeAllPendingNotificationRequests(&self);
146
147        #[cfg(all(feature = "UNNotification", feature = "block2"))]
148        #[unsafe(method(getDeliveredNotificationsWithCompletionHandler:))]
149        #[unsafe(method_family = none)]
150        pub unsafe fn getDeliveredNotificationsWithCompletionHandler(
151            &self,
152            completion_handler: &block2::Block<dyn Fn(NonNull<NSArray<UNNotification>>)>,
153        );
154
155        #[unsafe(method(removeDeliveredNotificationsWithIdentifiers:))]
156        #[unsafe(method_family = none)]
157        pub unsafe fn removeDeliveredNotificationsWithIdentifiers(
158            &self,
159            identifiers: &NSArray<NSString>,
160        );
161
162        #[unsafe(method(removeAllDeliveredNotifications))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn removeAllDeliveredNotifications(&self);
165
166        #[cfg(feature = "block2")]
167        #[unsafe(method(setBadgeCount:withCompletionHandler:))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn setBadgeCount_withCompletionHandler(
170            &self,
171            new_badge_count: NSInteger,
172            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
173        );
174    );
175}
176
177/// Methods declared on superclass `NSObject`.
178impl UNUserNotificationCenter {
179    extern_methods!(
180        #[unsafe(method(new))]
181        #[unsafe(method_family = new)]
182        pub unsafe fn new() -> Retained<Self>;
183    );
184}
185
186/// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions?language=objc)
187// NS_OPTIONS
188#[repr(transparent)]
189#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
190pub struct UNNotificationPresentationOptions(pub NSUInteger);
191bitflags::bitflags! {
192    impl UNNotificationPresentationOptions: NSUInteger {
193        #[doc(alias = "UNNotificationPresentationOptionBadge")]
194        const Badge = 1<<0;
195        #[doc(alias = "UNNotificationPresentationOptionSound")]
196        const Sound = 1<<1;
197#[deprecated]
198        #[doc(alias = "UNNotificationPresentationOptionAlert")]
199        const Alert = 1<<2;
200        #[doc(alias = "UNNotificationPresentationOptionList")]
201        const List = 1<<3;
202        #[doc(alias = "UNNotificationPresentationOptionBanner")]
203        const Banner = 1<<4;
204    }
205}
206
207unsafe impl Encode for UNNotificationPresentationOptions {
208    const ENCODING: Encoding = NSUInteger::ENCODING;
209}
210
211unsafe impl RefEncode for UNNotificationPresentationOptions {
212    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
213}
214
215/// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptionnone?language=objc)
216pub static UNNotificationPresentationOptionNone: UNNotificationPresentationOptions =
217    UNNotificationPresentationOptions(0);
218
219extern_protocol!(
220    /// [Apple's documentation](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate?language=objc)
221    pub unsafe trait UNUserNotificationCenterDelegate: NSObjectProtocol {
222        #[cfg(all(feature = "UNNotification", feature = "block2"))]
223        #[optional]
224        #[unsafe(method(userNotificationCenter:willPresentNotification:withCompletionHandler:))]
225        #[unsafe(method_family = none)]
226        unsafe fn userNotificationCenter_willPresentNotification_withCompletionHandler(
227            &self,
228            center: &UNUserNotificationCenter,
229            notification: &UNNotification,
230            completion_handler: &block2::Block<dyn Fn(UNNotificationPresentationOptions)>,
231        );
232
233        #[cfg(all(feature = "UNNotificationResponse", feature = "block2"))]
234        #[optional]
235        #[unsafe(method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:))]
236        #[unsafe(method_family = none)]
237        unsafe fn userNotificationCenter_didReceiveNotificationResponse_withCompletionHandler(
238            &self,
239            center: &UNUserNotificationCenter,
240            response: &UNNotificationResponse,
241            completion_handler: &block2::Block<dyn Fn()>,
242        );
243
244        #[cfg(feature = "UNNotification")]
245        #[optional]
246        #[unsafe(method(userNotificationCenter:openSettingsForNotification:))]
247        #[unsafe(method_family = none)]
248        unsafe fn userNotificationCenter_openSettingsForNotification(
249            &self,
250            center: &UNUserNotificationCenter,
251            notification: Option<&UNNotification>,
252        );
253    }
254);