UserNotifications

2018-10-18  本文已影响10人  Hunter琼

功能:

trigger:
1 UNTimeIntervalNotificationTrigger:一段时间触发

 UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:YES];

 UNNotificationRequest *requestNotif = [UNNotificationRequest   requestWithIdentifier:identifier content:context trigger:trigger];
 [notCenter addNotificationRequest:requestNotif withCompletionHandler:^(NSError * _Nullable error) {

}];

2 UNCalendarNotificationTrigger:设置规定的时间点提醒

 NSDateComponents *components = [[NSDateComponents alloc]init];
 NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
 NSDate *date = [gregorianCalendar dateFromComponents:components];
 NSInteger weekday = [gregorianCalendar component:NSCalendarUnitWeekday fromDate:date];
 components.weekday = weekday;
 components.hour  = 12;
 UNCalendarNotificationTrigger *commTrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
 UNNotificationRequest *requestNotif = [UNNotificationRequest   requestWithIdentifier:identifier content:context trigger:commTrigger];
 [notCenter addNotificationRequest:requestNotif withCompletionHandler:^(NSError * _Nullable error) {
 
 }];

3 UNLocationNotificationTrigger:位置通知提醒

 CLLocationCoordinate2D cllLoaction =
 CLLocationCoordinate2DMake(24, 120);
 CLCircularRegion *region = [[CLCircularRegion alloc]initWithCenter:cllLoaction radius:200 identifier:@"id"];
 region.notifyOnEntry = YES;
 region.notifyOnExit = YES;
 UNLocationNotificationTrigger *locationTrigger = [UNLocationNotificationTrigger triggerWithRegion:region repeats:NO];

补充 ios8 ios9 pushAPI:

 在ios8中,给push增加用户操作,
 到了ios9中,苹果增加了快速回复功能,进一步提高了通知的性能(typedef NS_ENUM(NSUInteger, UIUserNotificationActionBehavior) {
 UIUserNotificationActionBehaviorDefault,        // the default action behavior
 UIUserNotificationActionBehaviorTextInput       // system provided action behavior, allows text input from the user
 } NS_ENUM_DEPRECATED_IOS(9_0, 10_0, "Use UserNotifications Framework's UNNotificationAction or UNTextInputNotificationAction") __TVOS_PROHIBITED)
 UIUserNotificationSettings
 UIUserNotificationAction
 UIUserNotificationCategory

源码地址:https://github.com/joinGitWenze/ios10-11-12_UserNotificationsUI

上一篇 下一篇

猜你喜欢

热点阅读