SwiftLocalNotification 1.0.3

SwiftLocalNotification 1.0.3

[SalarSoleimani] 维护。



SwiftLocalNotification

易于使用,轻松在 Swift 中推送本地通知。

CI Status Version License Platform

安装

SwiftLocalNotification 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'SwiftLocalNotification'

演示

用法示例

// set the delegate to get the UNUserNotificationCenter delegates
let scheduler = SwiftLocalNotification(delegate: self) 

// you can set the identifier to empty and it will generate a random UUID 
let sampleNotification = SwiftLocalNotificationModel(title: "sampleTitle", body: "sampleBody", subtitle: nil, date: Date().next(seconds: 5), repeating: .none, identifier: "", soundName: nil, badge: 5)

// you can add the action button for your notification by easy 3 steps, but always remember do it before scheduling notification
let snoozeAction = UNNotificationAction(identifier: "snoozeAction", title: "Snooze in 2 minutes", options: [.authenticationRequired, .foreground])
let category = SwiftLocalNotificationCategory(categoryIdentifier: "snooze", actions: [snoozeAction])
category.set(forNotifications: sampleNotification)

// finally schedule the notification
scheduler.schedule(sampleNotification)

要运行示例项目,请先克隆仓库,然后从 Example 目录中运行 pod install

用例

获取通知隐私权限状态,请求推送通知的权限。

var permissionStatus: PermissionStatus { get }
func requestPermission(completion: @escaping (PermissionStatus) -> Void)

获取所有和特定的计划或已发送的通知,获取计划通知的数量。

func getAllScheduledNotifications() -> [SwiftLocalNotificationModel]
func getAllDeliveredNotifications() -> [SwiftLocalNotificationModel]
func getScheduled(notificationId id: String) -> SwiftLocalNotificationModel?
func getDelivered(notificationId id: String) -> SwiftLocalNotificationModel?
func getScheduledNotificationsCount() -> Int

计划通知

func schedule(notification notif: SwiftLocalNotificationModel) -> String?

编辑现有通知

func reSchedule(notification notif: SwiftLocalNotificationModel) -> String?

计划从特定时间开始每天的一条通知,例如“08:00”,到一个特定时间,并确定用户会收到多少次通知。

func scheduleDaily(notifications notif: SwiftLocalNotificationModel, fromTime: Date, toTime: Date, howMany: Int) -> [String]?

在两个特定日期之间计划一系列通知

func scheduleDaily(notifications notifs: [SwiftLocalNotificationModel], fromTime: Date, toTime: Date) -> [String]?

通过在起始日期后添加间隔来在两个特定日期之间计划一个通知

func schedule(notification notif: SwiftLocalNotificationModel, fromDate: Date, toDate: Date, interval: TimeInterval) -> String?

简单推送通知

func push(notification notif: SwiftLocalNotificationModel, secondsLater seconds: TimeInterval) -> String?)

设置应用徽标

func setApplicationBadge(_ option: BadgeOption, value: Int)

取消通知

func cancelAllNotifications()
func cancel(notificationIds: String...)

作者

| “关注 @salarsoleimani Twitter” |

| “给我发邮件” |

许可证

SwiftLocalNotification 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。