LocalNotificationScheduler 1.1

LocalNotificationScheduler 1.1

harish 维护。



  • harishchopra86

LocalNotificationScheduler

简介

LocalNotificationScheduler 是一个更简单的在项目中安排本地通知的方法。它可以通过一行代码安排不同类型的本地通知。

要求

  • Swift 4.2+
  • iOS 10.0+
  • Xcode 9.0+

安装

CocoaPods

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

pod 'LocalNotificationScheduler'

并在您使用库的页面中导入库

import LocalNotificationScheduler

使用指南

LocalNotificationScheduler 提供了三种方法来规划通知。每个方法都有一个可选的完成处理程序,如果规划通知时出现任何问题,则返回错误。错误可以是普通通知中的通知权限错误或区域监控通知中的位置权限错误。

要规划通知,可以使用共享实例

NotificationScheduler.shared

或者如果您想自己处理代理方法,可以创建自己的实例

let scheduler = NotificationScheduler(withDelegate: self)

规划日历通知

  • 以下方法可以用来在特定的日期时间触发通知。
  • 用户可以设置只有日期、重复、标识符和标题的通知。
let date = NSDate().addingTimeInterval(100)
NotificationScheduler.shared.scheduleNotificationWithFireDate(date as Date, repeatInterval:.hour, identifier: "hourly_repeating", title: "Hours Repeat")
  • 或者用户可以使用某些/所有参数来规划通知。大多数参数都是可选的,因此可以从函数中省略。
import UserNotifications

NotificationScheduler.shared.scheduleNotificationWithFireDate(date as Date, repeatInterval: .month, identifier: "monthly_repeating", title: "This notification repeats every month", subTitle: "This notification repeats every month", body: "This notification repeats every month", badge: NSNumber(value: 10), categoryIdentifier: "categortOne", threadIdentifier: "threadOne", launchImageName: nil, sound: UNNotificationSound.default, userInfo: ["paramOne": 10], attachments: []) { (error) in

}

规划时间间隔通知

  • 此方法可以用来规划在指定时间间隔秒后触发的通知。
NotificationScheduler.shared.scheduleNotificationWithTimeInterval(200, repeats: true, identifier: "time_interval", title: "This notification fires after 200 seconds.", subTitle: "This notification fires after 200 seconds.", completion: { error in
print(error)
})
})

规划区域监控通知

  • 在开始使用此方法规划任何通知之前,您的应用程序必须拥有使用 Core Location 的权限,并且必须有在应用程序使用时允许的权限。如果您没有位置授权,则此方法将抛出错误。
  • 此方法可以用来规划监控圆形区域的通知。
import CoreLocation

let toBeMonitoredRegion = CLCircularRegion(center: CLLocationCoordinate2DMake(48.424080, -123.363826), radius: 1000, identifier: "home")
toBeMonitoredRegion.notifyOnExit = true
toBeMonitoredRegion.notifyOnEntry = true
NotificationScheduler.shared.scheduleNotificationWithRegion(toBeMonitoredRegion, repeats: true, identifier: "region_home", title: "You have entered/exited your home")

作者

harishchopra86,[email protected][email protected]

许可协议

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