iOS 10 本地推送UNUserNotificationCenter
2016-12-09 10:42
411 查看
一:首先在AppDelegate.m中注册本地通知
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (!error) { NSLog(@"request authorization succeeded!"); } }];
二:发送推送消息
-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message{ WCLog(@"接收到消息----%@",message); if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { WCLog(@"------------在后台"); UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init]; content.title = [NSString localizedUserNotificationStringForKey:message.fromStr arguments:nil]; content.body = [NSString localizedUserNotificationStringForKey:message.body arguments:nil]; content.sound = [UNNotificationSound defaultSound]; // Deliver the notification in five seconds. UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" content:content trigger:trigger]; // Schedule the notification. UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { }]; } }
相关文章推荐
- ios推送:本地通知UILocalNotification
- iOS推送之本地推送(iOS Notification Of Local Notification)
- iOS-本地推送之UserNotifications(iOS 10)
- iOS 10 添加本地推送(Local Notification)
- ios推送:本地通知UILocalNotification
- IOS本地推送通知的一些属性 UILocalNotification
- iOS 10本地推送
- 【WWDC2016 Session】iOS 10 推送Notification新特性
- iOS推送:本地通知UILocalNotification
- iOS 本地推送 UILocalNotification
- iOS --- 本地推送通知 UILocalNotification
- WWDC2016 Session笔记 - iOS 10 推送Notification新特性
- ios推送:本地通知UILocalNotification
- iOS 本地推送 UILocalNotification
- iOS本地推送通知UILocalNotification(可以用做类似闹钟提醒)
- iOS推送 之 本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- iOS 10 添加本地推送(Local Notification)
- iOS推送之本地通知UILocalNotification
- iOS推送:本地通知UILocalNotification