创建本地通知

1、在APPdelegate里面注册本地通知
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]];
//2、创建本地通知
    UILocalNotification *notification = [[UILocalNotification alloc]init];
    //时区
    notification.timeZone = [NSTimeZone defaultTimeZone];
    //开启通知时间
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    //重复间隔
    notification.repeatInterval = kCFCalendarUnitMinute;
    //重复的日历
    notification.repeatCalendar = [NSCalendar currentCalendar];/**<  当前的日历 */
    //通知标题
    notification.alertTitle = @"该吃药了";
    //通知内容
    notification.alertBody = @"尊敬的xx,你要吃xx药了";
    
    notification.applicationIconBadgeNumber = 3;
    
    notification.soundName = UILocalNotificationDefaultSoundName;
    
    //添加
    
    [[UIApplication sharedApplication]scheduleLocalNotification:notification];
    
    //移除
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

通知使用完以后需要移除

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 推送通知和NSNotification区别:NSNotification是抽象的,不可见的推送通知是可见的(能用肉...
    ShenYj阅读 3,973评论 0 3
  • 本地通知是由本地应用触发的,它是基于时间行为的一种通知形式,例如闹钟定时、待办事项提醒,又或者一个应用在一段时候后...
    成语笔记阅读 1,898评论 0 0
  • 介绍一下iOS10的通知新功能,用户体验的提升和开发者能够发挥的地方非常多,使得iOS更具有竞争力。 1.iOS ...
    F麦子阅读 9,324评论 3 4
  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 11,594评论 1 8
  • 有声广播去除人声和背景音乐,只剩模拟声,那是一种怎样的相遇。 18.00。下班回家,把手机放好在牛仔裤口袋,发动摩...
    陈锦辉阅读 1,040评论 0 1