待办事项提醒功能开发(一)

Author Avatar
XibHe 3月 13, 2017
  • 在其它设备中阅读本文章

业务需求

根据用户所添加某件商品的生产日期和保质期天数计算商品的过期日期,在过期前的时间内,用户可以设置提醒的具体时间点和提醒频次,系统根据用户设置的提醒时间和提醒频次通知用户某某商品该使用了。具体操作步骤如下:

  • 新增一个提醒事项的名称,这个名称将作为待完成事项显示在任务列表中,可以快速勾选完成;
  • 在保质期限一栏,点击生产日期一栏,弹出年月日的日期选择器用于日期的选择;
  • 点击保质期天数一栏,弹出用于输入保质期天数的输入控件,保质期单位可以是天,月,年;
  • 如果保质期为30天以内,默认开启智能保质期提醒;如果超过30天,则关闭智能提醒,需要有手动设置结束提醒的具体时间及提醒频率;
  • 在提醒设置一栏,根据生产日期和保质期天数自动计算出到期的具体日期,用户点击时间一栏,弹出时间的选择控件用于选择触发提醒的时间点,用户也可以设置提醒频次;

需要考虑的技术点

结合需求需要考虑如下几个问题:

  • 本地通知的运行机制是什么?
  • 如何自定义通知的频率?
  • 如何移除到期的通知提醒?
  • 当用户编辑一个已经存在的提醒任务时,如何根据用户修改后的日期,频率等参数,更新现有的通知提醒频次,触发时间,日期等属性?
  • 当切换用户或者用户退出登录后,如何操作之前已经添加的通知提醒?
  • 通知提醒数据的持久化?

本地通知相关点

使用本地通知提醒用户,而本地通知有些地方在使用时需要注意,如下:

1.本地通知是有操作系统统一调度的,只有在应用退出到后台或者关闭才能收到通知;
2.本地通知的数量是有限制的,最近的本地通知最多只能有64个,超过这个数量将被系统忽略;
3.如果想要移除本地通知可以调用UIApplication的cancelLocalNotification:或cancelAllLocalNotifications移除指定通知或所有通知;
4.通知对应的NScalendarunit属性,可以通过该属性操作提醒的频率;

NScalendarunit的具体属性如下:

typedef NS_OPTIONS(NSUInteger, NSCalendarUnit) {
        NSCalendarUnitEra                = kCFCalendarUnitEra,
        NSCalendarUnitYear               = kCFCalendarUnitYear,
        NSCalendarUnitMonth              = kCFCalendarUnitMonth,
        NSCalendarUnitDay                = kCFCalendarUnitDay,
        NSCalendarUnitHour               = kCFCalendarUnitHour,
        NSCalendarUnitMinute             = kCFCalendarUnitMinute,
        NSCalendarUnitSecond             = kCFCalendarUnitSecond,
        NSCalendarUnitWeekday            = kCFCalendarUnitWeekday,
        NSCalendarUnitWeekdayOrdinal     = kCFCalendarUnitWeekdayOrdinal,
        NSCalendarUnitQuarter            NS_ENUM_AVAILABLE(10_6, 4_0) = kCFCalendarUnitQuarter,
        NSCalendarUnitWeekOfMonth        NS_ENUM_AVAILABLE(10_7, 5_0) = kCFCalendarUnitWeekOfMonth,
        NSCalendarUnitWeekOfYear         NS_ENUM_AVAILABLE(10_7, 5_0) = kCFCalendarUnitWeekOfYear,
        NSCalendarUnitYearForWeekOfYear  NS_ENUM_AVAILABLE(10_7, 5_0) = kCFCalendarUnitYearForWeekOfYear,
        NSCalendarUnitNanosecond         NS_ENUM_AVAILABLE(10_7, 5_0) = (1 << 15),
        NSCalendarUnitCalendar           NS_ENUM_AVAILABLE(10_7, 4_0) = (1 << 20),
        NSCalendarUnitTimeZone           NS_ENUM_AVAILABLE(10_7, 4_0) = (1 << 21),

    NSEraCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitEra instead") = NSCalendarUnitEra,
    NSYearCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitYear instead") = NSCalendarUnitYear,
    NSMonthCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitMonth instead") = NSCalendarUnitMonth,
    NSDayCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitDay instead") = NSCalendarUnitDay,
    NSHourCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitHour instead") = NSCalendarUnitHour,
    NSMinuteCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitMinute instead") = NSCalendarUnitMinute,
    NSSecondCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitSecond instead") = NSCalendarUnitSecond,
    NSWeekCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear, depending on which you mean") = kCFCalendarUnitWeek,
    NSWeekdayCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitWeekday instead") = NSCalendarUnitWeekday,
    NSWeekdayOrdinalCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_4, 10_10, 2_0, 8_0, "Use NSCalendarUnitWeekdayOrdinal instead") = NSCalendarUnitWeekdayOrdinal,
    NSQuarterCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_6, 10_10, 4_0, 8_0, "Use NSCalendarUnitQuarter instead") = NSCalendarUnitQuarter,
    NSWeekOfMonthCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_7, 10_10, 5_0, 8_0, "Use NSCalendarUnitWeekOfMonth instead") = NSCalendarUnitWeekOfMonth,
    NSWeekOfYearCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_7, 10_10, 5_0, 8_0, "Use NSCalendarUnitWeekOfYear instead") = NSCalendarUnitWeekOfYear,
    NSYearForWeekOfYearCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_7, 10_10, 5_0, 8_0, "Use NSCalendarUnitYearForWeekOfYear instead") = NSCalendarUnitYearForWeekOfYear,
    NSCalendarCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_7, 10_10, 4_0, 8_0, "Use NSCalendarUnitCalendar instead") = NSCalendarUnitCalendar,
    NSTimeZoneCalendarUnit NS_CALENDAR_ENUM_DEPRECATED(10_7, 10_10, 4_0, 8_0, "Use NSCalendarUnitTimeZone instead") = NSCalendarUnitTimeZone,
};

步骤说明

使用sqlite3进行通知提醒相关数据的持久化。大概的思路如下:

新增提醒任务:

1.插入保质期提醒任务表
2.插入通知表
3.插入通知log表
4.上传服务器通知提醒数据

编辑提醒任务:

1.更新保质期提醒任务表
2.更新通知表
3.更新通知log表
4.上传服务器编辑后的通知提醒数据

需要注意本地通知的官方文档是否有最近的跟新 ,待续……

–EOF–

若无特别说明,本站文章均为原创,转载请保留链接,谢谢