Skip to content

Notification

FengYan枫炎 edited this page Jun 30, 2025 · 3 revisions

Notification

提供了对 iOS 本地通知系统的访问,包括初始化通知系统、推送定时通知、移除待定通知等功能。

本地定时通知需要在Apple Dev网站配置App的相关权限,具体方法查找互联网。

方法

void Initialize()

初始化通知系统,不需要显式调用,当调用类中的其他方法时会自动初始化。

void PushNotification(string msg, string title, string identifier, int delay)

推送本地定时通知。

  • msg – 通知的内容。
  • title – 通知的标题。
  • identifier – 为通知指定的标识符,相同的标识符会被系统判定为同一个通知。
  • delay – 延迟的时间,单位为秒。通知将在延迟后推送。

void PushNotification(string msg, string title, string identifier, int delay, bool repeats)

上面的重载版本,支持设置repeats,循环推送通知

void PushNotification(string msg, string title, string identifier, in NSDateComponents dateComp)

支持在指定日期或时间触发通知,见 Apple UNCalendarNotificationTrigger

void PushNotification(string msg, string title, string identifier, in NSDateComponents dateComp)

上面的重载版本,支持设置repeats,可通过NSCalendarUnit指定在何时循环推送通知

用例

DateTime tmr= DateTime.Today.AddDays(1); //明天
var component = new NSDateComponents(NSCalendarUnit.Weekday | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, tmr);
Notification.PushNotification("通知内容", "通知标题(可留空string)", "通知标识符", component , true);

参考

void RemovePendingNotifications(string identifier)

移除某个待定通知。

  • identifier – 要移除的通知的标识符。

void RemoveAllPendingNotifications()

移除所有待定通知。

Clone this wiki locally