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

    }

  • 相关阅读:
    How to install php 7.x on CentOS 7
    Azure新建的CentOS设置root账户的密码
    远程激活.NET REFLECTOR(不能断网)
    C# WebApi 配置复杂路由不生效的问题
    在Mac上激活Adobe产品
    WIN10更新后出现无法联网的问题
    Mac安装SSHFS挂载远程服务器上的文件夹到本地
    输入三个数值,输出其中的最大值和最小值
    登录接口,只为自己能尽快吐槽一下这段代码
    随手记
  • 原文地址:https://www.cnblogs.com/zhujin/p/3998773.html
Copyright © 2020-2023  润新知