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