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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
#[cfg(feature = "block2")]
use block2::*;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UNAuthorizationOptions(pub NSUInteger);
impl UNAuthorizationOptions {
    pub const UNAuthorizationOptionBadge: Self = Self(1 << 0);
    pub const UNAuthorizationOptionSound: Self = Self(1 << 1);
    pub const UNAuthorizationOptionAlert: Self = Self(1 << 2);
    pub const UNAuthorizationOptionCarPlay: Self = Self(1 << 3);
    pub const UNAuthorizationOptionCriticalAlert: Self = Self(1 << 4);
    pub const UNAuthorizationOptionProvidesAppNotificationSettings: Self = Self(1 << 5);
    pub const UNAuthorizationOptionProvisional: Self = Self(1 << 6);
    #[deprecated = "Announcement authorization is always included"]
    pub const UNAuthorizationOptionAnnouncement: Self = Self(1 << 7);
    #[deprecated = "Use time-sensitive entitlement"]
    pub const UNAuthorizationOptionTimeSensitive: Self = Self(1 << 8);
}

unsafe impl Encode for UNAuthorizationOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for UNAuthorizationOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

pub static UNAuthorizationOptionNone: UNAuthorizationOptions = UNAuthorizationOptions(0);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UNUserNotificationCenter;

    unsafe impl ClassType for UNUserNotificationCenter {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSObjectProtocol for UNUserNotificationCenter {}

extern_methods!(
    unsafe impl UNUserNotificationCenter {
        #[method_id(@__retain_semantics Other delegate)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Id<ProtocolObject<dyn UNUserNotificationCenterDelegate>>>;

        #[method(setDelegate:)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn UNUserNotificationCenterDelegate>>,
        );

        #[method(supportsContentExtensions)]
        pub unsafe fn supportsContentExtensions(&self) -> bool;

        #[method_id(@__retain_semantics Other currentNotificationCenter)]
        pub unsafe fn currentNotificationCenter() -> Id<UNUserNotificationCenter>;

        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Id<Self>;

        #[cfg(feature = "block2")]
        #[method(requestAuthorizationWithOptions:completionHandler:)]
        pub unsafe fn requestAuthorizationWithOptions_completionHandler(
            &self,
            options: UNAuthorizationOptions,
            completion_handler: &Block<dyn Fn(Bool, *mut NSError)>,
        );

        #[cfg(feature = "UNNotificationCategory")]
        #[method(setNotificationCategories:)]
        pub unsafe fn setNotificationCategories(&self, categories: &NSSet<UNNotificationCategory>);

        #[cfg(all(feature = "UNNotificationCategory", feature = "block2"))]
        #[method(getNotificationCategoriesWithCompletionHandler:)]
        pub unsafe fn getNotificationCategoriesWithCompletionHandler(
            &self,
            completion_handler: &Block<dyn Fn(NonNull<NSSet<UNNotificationCategory>>)>,
        );

        #[cfg(all(feature = "UNNotificationSettings", feature = "block2"))]
        #[method(getNotificationSettingsWithCompletionHandler:)]
        pub unsafe fn getNotificationSettingsWithCompletionHandler(
            &self,
            completion_handler: &Block<dyn Fn(NonNull<UNNotificationSettings>)>,
        );

        #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
        #[method(addNotificationRequest:withCompletionHandler:)]
        pub unsafe fn addNotificationRequest_withCompletionHandler(
            &self,
            request: &UNNotificationRequest,
            completion_handler: Option<&Block<dyn Fn(*mut NSError)>>,
        );

        #[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
        #[method(getPendingNotificationRequestsWithCompletionHandler:)]
        pub unsafe fn getPendingNotificationRequestsWithCompletionHandler(
            &self,
            completion_handler: &Block<dyn Fn(NonNull<NSArray<UNNotificationRequest>>)>,
        );

        #[method(removePendingNotificationRequestsWithIdentifiers:)]
        pub unsafe fn removePendingNotificationRequestsWithIdentifiers(
            &self,
            identifiers: &NSArray<NSString>,
        );

        #[method(removeAllPendingNotificationRequests)]
        pub unsafe fn removeAllPendingNotificationRequests(&self);

        #[cfg(all(feature = "UNNotification", feature = "block2"))]
        #[method(getDeliveredNotificationsWithCompletionHandler:)]
        pub unsafe fn getDeliveredNotificationsWithCompletionHandler(
            &self,
            completion_handler: &Block<dyn Fn(NonNull<NSArray<UNNotification>>)>,
        );

        #[method(removeDeliveredNotificationsWithIdentifiers:)]
        pub unsafe fn removeDeliveredNotificationsWithIdentifiers(
            &self,
            identifiers: &NSArray<NSString>,
        );

        #[method(removeAllDeliveredNotifications)]
        pub unsafe fn removeAllDeliveredNotifications(&self);

        #[cfg(feature = "block2")]
        #[method(setBadgeCount:withCompletionHandler:)]
        pub unsafe fn setBadgeCount_withCompletionHandler(
            &self,
            new_badge_count: NSInteger,
            completion_handler: Option<&Block<dyn Fn(*mut NSError)>>,
        );
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UNUserNotificationCenter {
        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Id<Self>;
    }
);

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UNNotificationPresentationOptions(pub NSUInteger);
impl UNNotificationPresentationOptions {
    pub const UNNotificationPresentationOptionBadge: Self = Self(1 << 0);
    pub const UNNotificationPresentationOptionSound: Self = Self(1 << 1);
    #[deprecated]
    pub const UNNotificationPresentationOptionAlert: Self = Self(1 << 2);
    pub const UNNotificationPresentationOptionList: Self = Self(1 << 3);
    pub const UNNotificationPresentationOptionBanner: Self = Self(1 << 4);
}

unsafe impl Encode for UNNotificationPresentationOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for UNNotificationPresentationOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

pub static UNNotificationPresentationOptionNone: UNNotificationPresentationOptions =
    UNNotificationPresentationOptions(0);

extern_protocol!(
    pub unsafe trait UNUserNotificationCenterDelegate: NSObjectProtocol {
        #[cfg(all(feature = "UNNotification", feature = "block2"))]
        #[optional]
        #[method(userNotificationCenter:willPresentNotification:withCompletionHandler:)]
        unsafe fn userNotificationCenter_willPresentNotification_withCompletionHandler(
            &self,
            center: &UNUserNotificationCenter,
            notification: &UNNotification,
            completion_handler: &Block<dyn Fn(UNNotificationPresentationOptions)>,
        );

        #[cfg(all(feature = "UNNotificationResponse", feature = "block2"))]
        #[optional]
        #[method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]
        unsafe fn userNotificationCenter_didReceiveNotificationResponse_withCompletionHandler(
            &self,
            center: &UNUserNotificationCenter,
            response: &UNNotificationResponse,
            completion_handler: &Block<dyn Fn()>,
        );

        #[cfg(feature = "UNNotification")]
        #[optional]
        #[method(userNotificationCenter:openSettingsForNotification:)]
        unsafe fn userNotificationCenter_openSettingsForNotification(
            &self,
            center: &UNUserNotificationCenter,
            notification: Option<&UNNotification>,
        );
    }

    unsafe impl ProtocolType for dyn UNUserNotificationCenterDelegate {}
);