Skip to content

Commit 9adf80d

Browse files
committed
Add properties for sound type support
1 parent 80c7231 commit 9adf80d

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

com.unity.mobile.notifications/Runtime/iOS/Plugins/UnityNotificationData.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ enum triggerType
1717
UNKNOWN_TRIGGER = -1,
1818
};
1919

20+
enum UnitySoundType
21+
{
22+
kSoundTypeDefault = 0,
23+
kSoundTypeCritical = 1,
24+
kSoundTypeRingtone = 2,
25+
kSoundTypeNone = 4,
26+
};
27+
2028
typedef struct iOSNotificationData
2129
{
2230
char* identifier;
@@ -26,6 +34,9 @@ typedef struct iOSNotificationData
2634
char* subtitle;
2735
char* categoryIdentifier;
2836
char* threadIdentifier;
37+
int soundType;
38+
float soundVolume;
39+
char* soundName;
2940

3041
void* userInfo;
3142
void* attachments;

com.unity.mobile.notifications/Runtime/iOS/Plugins/UnityNotificationData.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void initiOSNotificationData(iOSNotificationData* notificationData)
7878
notificationData->subtitle = NULL;
7979
notificationData->categoryIdentifier = NULL;
8080
notificationData->threadIdentifier = NULL;
81+
notificationData->soundType = kSoundTypeDefault;
82+
notificationData->soundVolume = -1.0f;
83+
notificationData->soundName = NULL;
8184
notificationData->triggerType = PUSH_TRIGGER;
8285
notificationData->userInfo = NULL;
8386
}
@@ -201,6 +204,9 @@ void freeiOSNotificationData(iOSNotificationData* notificationData)
201204
if (notificationData->threadIdentifier != NULL)
202205
free(notificationData->threadIdentifier);
203206

207+
if (notificationData->soundName != NULL)
208+
free(notificationData->soundName);
209+
204210
if (notificationData->userInfo != NULL)
205211
{
206212
NSDictionary* userInfo = (__bridge_transfer NSDictionary*)notificationData->userInfo;

com.unity.mobile.notifications/Runtime/iOS/iOSNotification.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ public enum PresentationOption
3232
Alert = 1 << 2,
3333
}
3434

35+
/// <summary>
36+
/// The type of sound to use for the notification.
37+
/// See Apple documentation for details.
38+
/// </summary>
39+
/// <see href="https://developer.apple.com/documentation/usernotifications/unnotificationsound?language=objc"/>
40+
public enum NotificationSoundType
41+
{
42+
/// <summary>
43+
/// Play the default sound.
44+
/// </summary>
45+
Default = 0,
46+
47+
/// <summary>
48+
/// Critical sound (bypass Do Not Disturb)
49+
/// </summary>
50+
Critical = 1,
51+
52+
/// <summary>
53+
/// Ringtone sound.
54+
/// </summary>
55+
Ringtone = 2,
56+
57+
/// <summary>
58+
/// No sound.
59+
/// </summary>
60+
None = 4,
61+
}
62+
3563
[StructLayout(LayoutKind.Sequential)]
3664
internal struct TimeTriggerData
3765
{
@@ -82,6 +110,9 @@ internal struct iOSNotificationData
82110
public string subtitle;
83111
public string categoryIdentifier;
84112
public string threadIdentifier;
113+
public Int32 soundType;
114+
public float soundVolume;
115+
public string soundName;
85116

86117
public IntPtr userInfo;
87118
public IntPtr attachments;
@@ -213,6 +244,36 @@ public int Badge
213244
set { data.badge = value; }
214245
}
215246

247+
/// <summary>
248+
/// The type of sound to be played.
249+
/// </summary>
250+
public NotificationSoundType SoundType
251+
{
252+
get { return (NotificationSoundType)data.soundType; }
253+
set { data.soundType = (int)value; }
254+
}
255+
256+
/// <summary>
257+
/// The name of the sound to be played. Use null for system default sound.
258+
/// See Apple documentation for named sounds and sound file placement.
259+
/// </summary>
260+
public string SoundName
261+
{
262+
get { return data.soundName; }
263+
set { data.soundName = value; }
264+
}
265+
266+
/// <summary>
267+
/// The volume for the sound. Use null to use the default volume.
268+
/// See Apple documentation for supported values.
269+
/// </summary>
270+
/// <see href="https://developer.apple.com/documentation/usernotifications/unnotificationsound/2963118-defaultcriticalsoundwithaudiovol?language=objc"/>
271+
public float? SoundVolume
272+
{
273+
get { return data.soundVolume < 0 ? null : data.soundVolume; }
274+
set { data.soundVolume = value == null ? -1.0f : value.Value; }
275+
}
276+
216277
/// <summary>
217278
/// Arbitrary string data which can be retrieved when the notification is used to open the app or is received while the app is running.
218279
/// </summary>

0 commit comments

Comments
 (0)