转发自:https://www.jianshu.com/p/e347f999ed95 //已经废除的
http://blog.csdn.net/three_zhang/article/details/70170215
http://www.cocoachina.com/ios/20160926/17645.html //详解篇
https://www.jianshu.com/p/c58f8322a278 //详解篇
在iOS10苹果废弃了之前的UILocalNotification,而采用了新的UserNotifications Framework来推送通知。现在先说一下iOS10之前的本地推送流程!
这里要说一点,就是iOS系统限制了注册本地推送的数量,最大的注册量为64条。
程序已被杀死时 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) { //添加处理代码 NSLog(@"666这里被调用"); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"程序已被杀死,点击通知栏调用" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil]; [alert show]; } return YES; }
先导入这个东西#import <UserNotifications/UserNotifications.h>
实现UNUserNotificationCenterDelegate代理方法:
第一个方法: -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ // 处理完成后条用 completionHandler ,用于指示在前台显示通知的形式 completionHandler(UNNotificationPresentationOptionSound); }
这个方法中的那句话就是,当应用在前台的时候,收到本地通知,是用什么方式来展现。系统给了三种形式:
typedef NS_OPTIONS(NSUInteger, UNNotificationPresentationOptions) { UNNotificationPresentationOptionBadge = (1 << 0), UNNotificationPresentationOptionSound = (1 << 1), UNNotificationPresentationOptionAlert = (1 << 2), }
第二个代理方法:
这个方法是在后台或者程序被杀死的时候,点击通知栏调用的,在前台的时候不会被调用
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil]; [alert show]; completionHandler(); }转载于:https://www.cnblogs.com/CodingMann/p/8183578.html
