本地通知,UILocalNotification

1,

-(void)setLocalNotification

{

    UILocalNotification *notification=[[UILocalNotificationalloc] init];

   NSDate *now=[NSDatenew];

        int period = 10;

        notification.fireDate = [now dateByAddingTimeInterval:period];

        notification.timeZone=[NSTimeZonedefaultTimeZone];

        notification.soundName = @"pig.caf";

        notification.alertBody = [NSStringstringWithFormat:@"时间到了!"];

        NSDictionary* info = [NSDictionarydictionaryWithObject:@"时间到了啊" forKey:@"闹钟"];

        notification.userInfo = info;

        [[UIApplicationsharedApplication] scheduleLocalNotification:notification];//注册一个notification也可以注册多个

}

2,程序未开 时回调

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];(之前保函的一些信息)

3,程序开着 时,回调

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification(

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];(同上)

 

a,本地通知 必然 会 在你设置通知的页面 和  appdelegate这两个类中 切换,应该会用到 至少两个代理,开始, 其它的页面动态设置代理需要 调用 appdelegate里面的方法(在程序启动的时候就要注册提醒的通知,还需要加一步,就是 需要 另一个类 把需要提醒的信息 写入到 缓存当中,或者 写入到 nsuserdefault当中,),后面是  提醒之后 的后续操作,appdelegate需要调用 其它方法的 代理。。。

1,开始 需要根据用户的设置 动态设置 提醒的时间和 个数,这块可以用个代理

2,一个问题就是 ,不管你设置吃药了没有,提醒都无效了

3,还有就是  那个声音持续多长时间,还是 等用户关闭声音后 才停止,如果等待用户出发,

4,简化了好多,如果 从今日提醒里面 提取时间的话,因为 今日提醒里面 显示的时间 是经过筛选,设置过了的时间,比如 每周二上午8点,而如果今天是周三,这个时间是不显示的,那么  每个 nslocalnotification 需要关注的就是 一个当中 有那几个 时间 点 即可。。。那么 问题就变的 简单些了。。。 

 

原文地址:https://www.cnblogs.com/guligei/p/3165155.html