1,使用UNUserNotificationCenter
(1)创建UNUserNotificationCenter,设置推送模式和代理。
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert|UNAuthorizationOptionSound|UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"succeeded!");
}
}];
center.delegate = self;
(2)设置推送内容
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"推送中心标题";
content.subtitle = @"副标题";
content.body = @"这是UNUserNotificationCenter信息中心";
content.badge = @20;
content.categoryIdentifier = @"categoryIdentifier";
// 需要解锁显示,红色文字。点击不会进app。
// UNNotificationActionOptionAuthenticationRequired = (1
关注
打赏