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
use objc::{msg_send, sel, sel_impl};
use crate::{
object,
objective_c_runtime::{macros::interface_impl, traits::PNSObject},
utils::to_bool,
};
object! {
/// The object for managing notification-related settings and the authorization status of your app.
unsafe pub struct UNNotificationSettings;
}
/// Constants indicating whether the app is allowed to schedule notifications.
#[repr(i64)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum UNAuthorizationStatus {
/// The user hasn't yet made a choice about whether the app is allowed to schedule notifications.
NotDetermined = 0,
/// The app isn't authorized to schedule or receive notifications.
Denied,
/// The app is authorized to schedule or receive notifications.
Authorized,
/// The application is provisionally authorized to post noninterruptive user notifications.
#[cfg(target_os = "ios")]
Provisional,
/// The app is authorized to schedule or receive notifications for a limited amount of time.
#[cfg(target_os = "ios")]
Ephemeral,
}
/// Constants that indicate the current status of a notification setting.
#[repr(i64)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum UNNotificationSetting {
/// The setting is not available to your app.
NotSupported = 0,
/// The setting is disabled.
Disabled,
/// The setting is enabled.
Enabled,
}
/// Constants indicating the presentation styles for alerts.
#[repr(i64)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum UNAlertStyle {
/// No alert.
None = 0,
/// Banner alerts.
Banner,
/// Modal alerts.
Alert,
}
/// Constants indicating the style previewing a notification's content.
#[repr(i64)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum UNShowPreviewsSetting {
/// The notification's content is always shown, even when the device is locked.
Always,
/// The notification's content is shown only when the device is unlocked.
WhenAuthenticated,
/// The notification's content is never shown, even when the device is unlocked
Never,
}
#[interface_impl(NSObject)]
impl UNNotificationSettings {
/* Getting the Authorization Status
*/
/// The app's ability to schedule and receive local and remote notifications.
#[property]
pub fn authorization_status(&self) -> UNAuthorizationStatus {
unsafe { msg_send![self.m_self(), authorizationStatus] }
}
/* Getting Device-Specific Settings
*/
/// The setting that indicates whether your app’s notifications appear in Notification Center.
#[property]
pub fn notification_center_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), notificationCenterSetting] }
}
/// The setting that indicates whether your app’s notifications appear on a device’s Lock screen.
#[property]
pub fn lock_screen_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), lockScreenSetting] }
}
/// The setting that indicates whether your app’s notifications appear in CarPlay.
#[property]
pub fn car_play_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), carPlaySetting] }
}
/// The authorization status for displaying alerts.
#[property]
pub fn alert_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), alertSetting] }
}
/// The setting that indicates whether badges appear on your app’s icon.
#[property]
pub fn badge_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), badgeSetting] }
}
/// The authorization status for playing sounds for incoming notifications.
#[property]
pub fn sound_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), soundSetting] }
}
/// The authorization status for playing sounds for critical alerts.
#[property]
pub fn critical_alert_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), criticalAlertSetting] }
}
/// The setting that indicates whether Siri can announce your app’s notifications.
#[property]
pub fn announcement_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), announcementSetting] }
}
/// The setting that indicates the system schedules the notification.
#[property]
pub fn scheduled_delivery_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), scheduledDeliverySetting] }
}
/// The setting that indicates the system treats the notification as time-sensitive.
#[property]
pub fn time_sensitive_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), timeSensitiveSetting] }
}
/* Getting Interface Settings
*/
/// The setting that indicates whether the app shows a preview of the notification's content.
#[property]
pub fn show_previews_setting(&self) -> UNShowPreviewsSetting {
unsafe { msg_send![self.m_self(), showPreviewsSetting] }
}
/// A Boolean value indicating the system displays a button for in-app notification settings.
#[property]
pub fn provides_app_notification_settings(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), providesAppNotificationSettings]) }
}
///
#[property]
pub fn direct_messages_setting(&self) -> UNNotificationSetting {
unsafe { msg_send![self.m_self(), directMessagesSetting] }
}
}