本地通知

+ (void)registerLocalNotification:(NSInteger)alertTime {

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

// 设置触发通知的时间

NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:alertTime];

NSLog(@"fireDate=%@",fireDate);

notification.fireDate = fireDate;

// 时区

notification.timeZone = [NSTimeZone defaultTimeZone];

// 设置重复的间隔

notification.repeatInterval = kCFCalendarUnitSecond;

// 通知内容

notification.alertBody =  @"该起床了...";

notification.applicationIconBadgeNumber = 1;

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

notification.soundName = UILocalNotificationDefaultSoundName;

// 通知参数

NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"开始学习iOS开发了" forKey:@"key"];

notification.userInfo = userDict;

// ios8后,需要添加这个注册,才能得到授权

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {

UIUserNotificationType type =  UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type

categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

// 通知重复提示的单位,可以是天、周、月

notification.repeatInterval = NSCalendarUnitDay;

} else {

// 通知重复提示的单位,可以是天、周、月

notification.repeatInterval = NSDayCalendarUnit;

}

// 执行通知注册

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

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

推荐阅读更多精彩内容

  • 许多集成的步骤个推官网都有了,这里只写关于推送的远程推送和本地通知的步骤和代码。APP在后台时:走苹果的APNS通...
    AllureJM阅读 2,772评论 1 9
  • //.h //注册 + (void)registerLocalNotification; //推送 + (UILo...
    CHADHEA阅读 343评论 0 0
  • 这是我写的第一篇简书文章,写的不好,希望大家多多指导,多多交流. iOS的本地通知,多用于定时发送通知,比如游戏中...
    FR_Zhang阅读 2,759评论 13 4
  • 本地通知是由本地应用触发的,它是基于时间行为的一种通知形式,例如闹钟定时、待办事项提醒,又或者一个应用在一段时候后...
    成语笔记阅读 285评论 0 0
  • 拖拉了半个多月才把这部电影看完,不喜欢不喜欢不喜欢,重要的事情得说三遍。从头至尾没看懂不知道当时mono给我推荐干...
    说吧_记忆阅读 360评论 0 0