objc2_user_notifications/generated/
UNUserNotificationCenter.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10#[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
48pub static UNAuthorizationOptionNone: UNAuthorizationOptions = UNAuthorizationOptions(0);
50
51extern_class!(
52 #[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 fn delegate(
67 &self,
68 ) -> Option<Retained<ProtocolObject<dyn UNUserNotificationCenterDelegate>>>;
69
70 #[unsafe(method(setDelegate:))]
74 #[unsafe(method_family = none)]
75 pub fn setDelegate(
76 &self,
77 delegate: Option<&ProtocolObject<dyn UNUserNotificationCenterDelegate>>,
78 );
79
80 #[unsafe(method(supportsContentExtensions))]
81 #[unsafe(method_family = none)]
82 pub fn supportsContentExtensions(&self) -> bool;
83
84 #[unsafe(method(currentNotificationCenter))]
85 #[unsafe(method_family = none)]
86 pub fn currentNotificationCenter() -> Retained<UNUserNotificationCenter>;
87
88 #[unsafe(method(init))]
89 #[unsafe(method_family = init)]
90 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
91
92 #[cfg(feature = "block2")]
93 #[unsafe(method(requestAuthorizationWithOptions:completionHandler:))]
94 #[unsafe(method_family = none)]
95 pub fn requestAuthorizationWithOptions_completionHandler(
96 &self,
97 options: UNAuthorizationOptions,
98 completion_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
99 );
100
101 #[cfg(feature = "UNNotificationCategory")]
102 #[unsafe(method(setNotificationCategories:))]
103 #[unsafe(method_family = none)]
104 pub fn setNotificationCategories(&self, categories: &NSSet<UNNotificationCategory>);
105
106 #[cfg(all(feature = "UNNotificationCategory", feature = "block2"))]
107 #[unsafe(method(getNotificationCategoriesWithCompletionHandler:))]
108 #[unsafe(method_family = none)]
109 pub fn getNotificationCategoriesWithCompletionHandler(
110 &self,
111 completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSSet<UNNotificationCategory>>)>,
112 );
113
114 #[cfg(all(feature = "UNNotificationSettings", feature = "block2"))]
115 #[unsafe(method(getNotificationSettingsWithCompletionHandler:))]
116 #[unsafe(method_family = none)]
117 pub fn getNotificationSettingsWithCompletionHandler(
118 &self,
119 completion_handler: &block2::DynBlock<dyn Fn(NonNull<UNNotificationSettings>)>,
120 );
121
122 #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
123 #[unsafe(method(addNotificationRequest:withCompletionHandler:))]
124 #[unsafe(method_family = none)]
125 pub fn addNotificationRequest_withCompletionHandler(
126 &self,
127 request: &UNNotificationRequest,
128 completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
129 );
130
131 #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
132 #[unsafe(method(getPendingNotificationRequestsWithCompletionHandler:))]
133 #[unsafe(method_family = none)]
134 pub fn getPendingNotificationRequestsWithCompletionHandler(
135 &self,
136 completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSArray<UNNotificationRequest>>)>,
137 );
138
139 #[unsafe(method(removePendingNotificationRequestsWithIdentifiers:))]
140 #[unsafe(method_family = none)]
141 pub fn removePendingNotificationRequestsWithIdentifiers(
142 &self,
143 identifiers: &NSArray<NSString>,
144 );
145
146 #[unsafe(method(removeAllPendingNotificationRequests))]
147 #[unsafe(method_family = none)]
148 pub fn removeAllPendingNotificationRequests(&self);
149
150 #[cfg(all(feature = "UNNotification", feature = "block2"))]
151 #[unsafe(method(getDeliveredNotificationsWithCompletionHandler:))]
152 #[unsafe(method_family = none)]
153 pub fn getDeliveredNotificationsWithCompletionHandler(
154 &self,
155 completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSArray<UNNotification>>)>,
156 );
157
158 #[unsafe(method(removeDeliveredNotificationsWithIdentifiers:))]
159 #[unsafe(method_family = none)]
160 pub fn removeDeliveredNotificationsWithIdentifiers(&self, identifiers: &NSArray<NSString>);
161
162 #[unsafe(method(removeAllDeliveredNotifications))]
163 #[unsafe(method_family = none)]
164 pub fn removeAllDeliveredNotifications(&self);
165
166 #[cfg(feature = "block2")]
167 #[unsafe(method(setBadgeCount:withCompletionHandler:))]
168 #[unsafe(method_family = none)]
169 pub fn setBadgeCount_withCompletionHandler(
170 &self,
171 new_badge_count: NSInteger,
172 completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
173 );
174 );
175}
176
177impl UNUserNotificationCenter {
179 extern_methods!(
180 #[unsafe(method(new))]
181 #[unsafe(method_family = new)]
182 pub unsafe fn new() -> Retained<Self>;
183 );
184}
185
186#[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 #[doc(alias = "UNNotificationPresentationOptionAlert")]
198#[deprecated]
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
215pub static UNNotificationPresentationOptionNone: UNNotificationPresentationOptions =
217 UNNotificationPresentationOptions(0);
218
219extern_protocol!(
220 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 fn userNotificationCenter_willPresentNotification_withCompletionHandler(
227 &self,
228 center: &UNUserNotificationCenter,
229 notification: &UNNotification,
230 completion_handler: &block2::DynBlock<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 fn userNotificationCenter_didReceiveNotificationResponse_withCompletionHandler(
238 &self,
239 center: &UNUserNotificationCenter,
240 response: &UNNotificationResponse,
241 completion_handler: &block2::DynBlock<dyn Fn()>,
242 );
243
244 #[cfg(feature = "UNNotification")]
245 #[optional]
246 #[unsafe(method(userNotificationCenter:openSettingsForNotification:))]
247 #[unsafe(method_family = none)]
248 fn userNotificationCenter_openSettingsForNotification(
249 &self,
250 center: &UNUserNotificationCenter,
251 notification: Option<&UNNotification>,
252 );
253 }
254);