wxr
2024-08-02 ea4b1f379fa052b1e044e1d67e85a8500cbd86ff
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
using System;
using UserNotifications;
 
namespace Other
{
    public class ScheduleLocalNotification
    {
        public void SetScheduleLocalNotification()
        {
            // 创建通知内容
            var content = new UNMutableNotificationContent
            {
                Title = "自定义铃声通知",
                Body = "这是带有自定义铃声的本地通知。",
                Sound = UNNotificationSound.GetSound("oldphone_mono.wav") // 替换为您的音频文件名
            };
 
            // 设置触发时间(例如,5秒后触发)
            var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(5, false);
 
            // 创建通知请求
            var request = UNNotificationRequest.FromIdentifier(Guid.NewGuid().ToString(), content, trigger);
 
            // 添加通知请求到通知中心
            UNUserNotificationCenter.Current.AddNotificationRequest(request, (error) =>
            {
                if (error != null)
                {
                    // 处理错误
                    Console.WriteLine($"添加通知失败: {error.LocalizedDescription}");
                }
            });
        }
 
    }
}