iOS 推送笔记
2015-11-02 09:04
495 查看
iOS 8,iOS 9 推送做了一些改变,以前的推送内容限制512B,现在扩充到2k吧。而且iOS以后推送注册方式也发生了改变! 主要是下面红色部分!我们要先注册用户通知。
注册本地通知:
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";//这组动作的唯一标示
扩展的操作
你可以在这里面操作
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(); }
你可以在这里面操作
相关文章推荐
- RunTime
- iOS应用内支付(IAP)的那些坑
- iOS实现简单的关灯游戏
- iOS SEL的理解与使用
- nagios
- ios中实现staggeringBeauty的效果(三)
- iOS-AutoLayout中动画使用的细节 和 iOS layout机制
- iOS-AutoLayout中动画使用的细节 和 iOS layout机制
- iOS把图片缓存到本地的几种方法
- iOS 并发与并行
- iOS 多线程详解
- iOS支付宝集成步骤;王刚韧的技术博客
- ios 精简日历
- IOS个人帐号推送证书创建
- iOS中可以设定时间自动消失提示框的三种实现方式
- 更改ios状态栏颜色
- iOS NSCondition结合代码以及项目进行详解
- iOS JSON 数据解析
- 蓝懿ioS 技术内容和心得交流 11.1 正反向
- 2015 iOS心得八 项目使用自定义的字体