rust_macios/user_notifications/
un_notification_sound.rs1use libc::c_float;
2use objc::{msg_send, sel, sel_impl};
3use rust_macios_objective_c_runtime_proc_macros::interface_impl;
4
5use crate::{
6 object,
7 objective_c_runtime::traits::{FromId, PNSObject},
8};
9
10use super::UNNotificationSoundName;
11
12object! {
13 unsafe pub struct UNNotificationSound;
15}
16
17#[interface_impl(NSObject)]
18impl UNNotificationSound {
19 #[property]
24 pub fn default_sound() -> UNNotificationSound {
25 unsafe { UNNotificationSound::from_id(msg_send![Self::m_class(), defaultSound]) }
26 }
27
28 #[method]
30 pub fn sound_named(name: UNNotificationSoundName) -> Self
31 where
32 Self: Sized + FromId,
33 {
34 unsafe { Self::from_id(msg_send![Self::m_class(), soundNamed: name]) }
35 }
36
37 #[property]
42 pub fn default_critical_sound() -> UNNotificationSound {
43 unsafe { UNNotificationSound::from_id(msg_send![Self::m_class(), defaultCriticalSound]) }
44 }
45
46 #[method]
48 pub fn default_critical_sound_with_audio_volume(volume: c_float) -> Self
49 where
50 Self: Sized + FromId,
51 {
52 unsafe {
53 Self::from_id(msg_send![
54 Self::m_class(),
55 defaultCriticalSoundWithAudioVolume: volume
56 ])
57 }
58 }
59
60 #[method]
62 pub fn critical_sound_named(name: UNNotificationSoundName) -> Self
63 where
64 Self: Sized + FromId,
65 {
66 unsafe { Self::from_id(msg_send![Self::m_class(), criticalSoundNamed: name]) }
67 }
68
69 #[method]
71 pub fn critical_sound_named_with_audio_volume(
72 name: UNNotificationSoundName,
73 volume: c_float,
74 ) -> Self
75 where
76 Self: Sized + FromId,
77 {
78 unsafe {
79 Self::from_id(
80 msg_send![Self::m_class(), criticalSoundNamed: name withAudioVolume: volume],
81 )
82 }
83 }
84
85 #[property]
89 pub fn default_ringtone_sound() -> UNNotificationSound {
90 unsafe { UNNotificationSound::from_id(msg_send![Self::m_class(), defaultRingtoneSound]) }
91 }
92
93 #[method]
97 pub fn ringtone_sound_named(name: UNNotificationSoundName) -> Self
98 where
99 Self: Sized + FromId,
100 {
101 unsafe { Self::from_id(msg_send![Self::m_class(), ringtoneSoundNamed: name]) }
102 }
103}