那是一个闷热的夏天,我会想起被色魔张大妈统治的恐惧,和每天十点签到的高潮。。。。
+ (void)registerLocalNotification{名字瞎取得不要在意这些细节。。
UILocalNotification *notification = [[UILocalNotificationalloc] init];
// 设置触发通知的时间
时间注意,since1970得到的是格林尼治时间早八点,所以需要几点通知算一下,你懂得,如下13*60*60代表延后13个小时也就是晚上21点
NSDate *fireDate = [NSDatedateWithTimeIntervalSince1970:13*60*60];
notification.fireDate = fireDate;
// 时区
notification.timeZone = [NSTimeZonedefaultTimeZone];
// 设置重复的间隔
自行设定间隔思密达
notification.repeatInterval =NSCalendarUnitDay;
// 通知内容
notification.alertBody = @"你今天学习了嘛";
设置程序图标小红点数字,不知为何用++ \+=都只保持1,不过这并不重要(大概。。。
notification.applicationIconBadgeNumber +=1;
// 通知被触发时播放的声音
notification.soundName =UILocalNotificationDefaultSoundName;
// 通知参数
NSDictionary *userDict = [NSDictionarydictionaryWithObject:@"test"forKey:@"key"];
notification.userInfo = userDict;
// 执行通知注册
[[UIApplicationsharedApplication] scheduleLocalNotification:notification];
}
iOS8后请加如下语句,可以在程序启动就请求授权,也可以按需加到自己需要获取授权的时候
//授权
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:type categories:nil];
[[UIApplicationsharedApplication]registerUserNotificationSettings:settings];