iOS 推送笔记
来源:互联网 发布:软件体系结构原理 编辑:程序博客网 时间:2024/04/28 21:26
iOS 8,iOS 9 推送做了一些改变,以前的推送内容限制512B,现在扩充到2k吧。而且iOS以后推送注册方式也发生了改变! 主要是下面红色部分!我们要先注册用户通知。
推送的扩张
这里当你的本地通知也加入扩展时
你可以在这里面操作
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init]; action1.title = @"删除"; action1.identifier = @"删除test"; action1.activationMode = UIUserNotificationActivationModeBackground; UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; action2.title = @"回复"; action2.identifier = @"回复test"; [action2 setBehavior:UIUserNotificationActionBehaviorTextInput]; action2.activationMode = UIUserNotificationActivationModeBackground; UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys.identifier = @"alert";//这组动作的唯一标示 [categorys setActions:@[action1,action2] forContext:UIUserNotificationActionContextMinimal]; <span style="color:#ff0000;"> UIUserNotificationType type = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge| UIUserNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:[NSSet setWithObject:categorys]]; [application registerForRemoteNotifications]; [application registerUserNotificationSettings:settings];</span> }
注册本地通知:
UILocalNotification *notification = [[UILocalNotification alloc] init]; NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:alertTime];//本地推送间隔多久时间发生 notification.fireDate = fireDate; notification.timeZone = [NSTimeZone defaultTimeZone];//当前时区 notification.repeatInterval = kCFCalendarUnitDay;//重复间隔 notification.alertBody = @"该起床了...";//通知栏显示的文字 notification.applicationIconBadgeNumber = 1;//APP数字 notification.soundName = UILocalNotificationDefaultSoundName;//声音 NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"开始学习iOS开发了" forKey:@"key"]; notification.userInfo = userDict;//参数字典 //按上面约定时间执行通知 //[[UIApplication sharedApplication] presentLocalNotificationNow:notification];//立刻执行 [[UIApplication sharedApplication] scheduleLocalNotification:notification];//按约定时间执行
推送的扩张
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init]; action.identifier = @"action";//按钮的标示 action.title=@"回复";//按钮的标题 [action setBehavior:UIUserNotificationActionBehaviorTextInput];//点击这个按钮会弹出输入框 action.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候启动程序 //action.authenticationRequired = YES;//是否需要解锁 action.destructive = YES;// UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; //第二按钮 action2.identifier = @"action2"; action2.title=@"Reject"; action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理 action.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略; action.destructive = YES; UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys.identifier = @"alert";//这组动作的唯一标示 [categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)]; UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:[NSSet setWithObjects:categorys, nil]];
这里当你的本地通知也加入扩展时
notification.category = @"alert"; 的标题必须与 categorys.identifier = @"alert";//这组动作的唯一标示
扩展的操作
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler{ if ([identifier isEqualToString:@"回复test"]) { NSInteger num = [responseInfo[UIUserNotificationActionResponseTypedTextKey] integerValue]; application.applicationIconBadgeNumber += num; NSLog(@"回复"); } else if([identifier isEqualToString:@"删除test"]) { application.applicationIconBadgeNumber = 90; NSLog(@"删除"); } completionHandler();}
你可以在这里面操作
0 0
- ios远程推送笔记
- iOS 推送笔记
- iOS 推送通知-笔记
- iOS学习笔记5-推送(信鸽推送)
- 【iOS学习笔记】远程推送
- IOS网络笔记--本地推送
- iOS学习笔记 推送通知
- iOS制作推送证书笔记
- ios学习笔记:ios推送细节
- IOS开发笔记5 -- 本地推送
- 杨小麦iOS学习笔记--远程推送
- iOS学习笔记22-推送通知
- iOS开发-极光推送SDK使用笔记
- 笔记 iOS消息推送 测试代码
- iOS推送 (百度推送)
- iOS推送 (百度推送)
- iOS- 推送极光推送
- iOS学习笔记27— IOS详细推送
- 玩转树莓派--树莓派准备工作
- Genymotion安装中文输入法
- 对霍夫直线变换返回的直线参数进行遍历
- JavaBeans
- Codevs 挂缀
- iOS 推送笔记
- Windows平台下安装MongoDB
- 2015暑期实习作品
- uboot ddr配置
- ACTION_POWER_DISCONNECTED广播使用解析
- JAVA学习5_Java NIO 报java.nio.charset.MalformedInputException: Input length = 1异常
- 用指针操作多维数组
- 咕咚登陆 注册 核心算法 上传步数【分析】
- K线战术精要——阻击涨停板