美文网首页
本地通知

本地通知

作者: 木马不在转 | 来源:发表于2016-05-16 17:36 被阅读24次

+ (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];

}

相关文章

  • iOS 通知的使用

    源地址 本地通知属于UIKit框架、推送通知属于Foundation框架。 本地通知 本地通知是由本地应用触发的,...

  • iOS10 通知框架总结

    通知分为本地通知和远端通知,这里着重介绍本地通知。本地通知有三个步骤 Appdelegate中申请通知权限 App...

  • 通知--本地通知

    本地通知是由本地应用触发的,它是基于时间行为的一种通知形式,例如闹钟定时、待办事项提醒,又或者一个应用在一段时候后...

  • iOS 本地推送通知

    本地推送通知 对本地通知的数量限制,iOS最多允许最近本地通知数量是64个,超过限制的本地通知将被iOS忽略。 a...

  • 本地推送通知、远程推送通知、激光推送

    title : 本地推送通知、远程推送通知、激光推送category : UI 本地推送通知、远程推送通知、激光...

  • UILocalNotification

    本文内容a.注册普通本地通知b.自定义操作的本地通知c.自定义可快捷回复的本地通知 注册普通本地通知 创建一个本地...

  • iOS14开发- 通知

    iOS 中的通知主要分为 2 种,本地通知和远程通知。 本地通知 使用步骤 导入UserNotifications...

  • iOS开发- 推送服务

    1,注册本地通知 使用本地通知之前是需要预先设置好通知的一些基本属性,然后向系统注册本地通知,通知会在设定好的时间...

  • 本地推送/本地通知

    一、本地推送/本地通知 是什么? (名称概念)本地推送,其实也就是本地通知,它们指的是同一种概念,只是叫法不同,下...

  • 本地通知

    iOS系统可支持本地通知和远程通知,一个通知在客户端收到的时候可能是一个通知窗体,可能会播放一段通知声音,还有可能...

网友评论

      本文标题:本地通知

      本文链接:https://www.haomeiwen.com/subject/akbbrttx.html