• 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();//处理完消息,最后一定要调用这个代码块

    }

  • 相关阅读:
    Networking with standalone containers
    记filebeat内存泄漏问题分析及调优
    原创-The Salt Master has rejected this minion's public key!解决方法
    原创-某次建表失败-ERROR 1101 (42000): BLOB/TEXT column can’t have a default value
    action命令-判断判断码是否正确
    docker-docker中用户uid异常导致权限不足
    非原创-docker 6种减小镜像大小的方式
    非原创-docker update
    原创-k8s 存活探针,就绪探针与启动探针
    原创-阿里elasticsearch数据迁移
  • 原文地址:https://www.cnblogs.com/zhujin/p/3998773.html
Copyright © 2020-2023  润新知