ios8消息快捷处理——暂无输入框
if (isiOS8)
{
//ios8的远程推送注册
NSSet *set = nil;
#if 1
//1.创建消息上面要添加的动作(按钮的形式显示出来)
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
action.identifier = @"action";//按钮的标示
action.title=@"Accept";//按钮的标题
action.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
// 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;
//2.创建动作(按钮)的类别集合
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = @"alert";//这组动作的唯一标示
[category setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)];
//
set = [NSSet setWithObjects:category, nil];
//远程通知测试 消息体: {"aps":{"alert":"Incoming call", "sound":"default", "badge": 1, "category":"alert"}}
//"category":"alert"必须对应 category.identifier = @"alert";
//本地通知测试
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:15];
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.alertBody=@"测试推送的快捷回复";
notification.category = @"alert";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
#endif
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:set]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}else
{
//ios8以前的远程推送注册
UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
}
}
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
{
//在没有启动本App时,收到服务器推送消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮
}
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
//在非本App界面时收到本地消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮,notification为消息内容
NSLog(@"%@----%@",identifier,notification);
completionHandler();//处理完消息,最后一定要调用这个代码块
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。