网上有很多资料关于IOS10推送的理论知识,下面我用代码加效果截图的方式来加深印象。
当我们在app前台的时候,我们通知栏是不会显示的。但是ios10提供了方法给我们可以在前台的时候,弹出通知栏。
那就是需要设置
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
并且实现代理方法。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert);
}
// The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from application:didFinishLaunchingWithOptions:.
-
(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler
{
completionHandler();
}
1下面我截图第一种通知
2分类通知当中的一种
3分类通知当中的另外一种
4带图片的通知 下滑还可以展示大图
5带gif的通知,这个gif我刚好用的自己录制的。
6带音频的通知
下面是代码
https://github.com/lijufengxin/UserLocalNotificationDemo