iOS UILocalNotification定时提醒

   UILocalNotification *notifity=[[UILocalNotification alloc] init];

//    NSString *strTimer = @"18:58";

//    NSDateFormatter *formattr=[[NSDateFormatter alloc] init];

//    //格式化时间

//    [formattr setDateFormat:@"HH:mm"];

//    //触发通知时间

//

//    NSDate *now=[formattr dateFromString:[NSString stringWithFormat:@"%@",strTimer]];

//    notifity.fireDate=now;

    

    

    NSDate *now2=[NSDate new];

    notifity.fireDate=[now2 addTimeInterval:10];

    

    

    //时区

    notifity.timeZone=[NSTimeZone defaultTimeZone];

    //通知重复提示的单位,可以是周(NSWeekdayCalendarUnit)分钟(NSMinuteCalendarUnit)秒(NSSecondCalendarUnit)月(NSMonthCalendarUnit)年(NSYearCalendarUnit)

    

    notifity.repeatInterval=NSCalendarUnitDay;

    

    //通知内容

    notifity.alertBody=@"这是一个通知";

    //通知触发时播放的声音

    notifity.soundName=UILocalNotificationDefaultSoundName;

    //如果要在通知栏中携带参数信息,可以使用下面的方式:

    

    NSDictionary *dic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];

    

    notifity.userInfo = dic;

    //如果软件是在运行中,则可以通过AppDelegate中的回调方法获取并处理参数信息:

    

    //执行通知注册

    

    

    [[UIApplication sharedApplication] scheduleLocalNotification:notifity];

   
    // 需要注意:iOS8系统变更了注册方法,需要在ApplicationDelegate里面注册通知才可以。

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){

        

        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];

        

    }

    

    //    可以通过两种方式取消注册的本地通知,一种是取消指定的通知,第二种是取消所有的注册通知:

    

//    [[UIApplication sharedApplication] cancelLocalNotification:localNotification];

//    [[UIApplication sharedApplication] cancelAllLocalNotifications];



转载地址:http://www.th7.cn/Program/IOS/201407/232425.shtml




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值