ios8.0 推送中的 categories

iOS 8.0 之后,在推送中新增加了categories,这是个什么意思呢?它只针对iphne锁屏的状态下。看图就明白了。

在ios8.0 以前(7.0~8.0):在锁屏的情况下,只会显示这样的推送界面:



但是 ios8.0 的系统可以这样:(向右滑动的,出现选择两个选择项)



代码中体现为:

使用了umeng的推送sdk,(所有的第三方推送都差不多,个人推荐友盟的推送,因为友盟的集成简单,比JPUSH还简单。其次是是友盟的数据统计与分析很强大)。


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //程序入口
    self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

 [UMessage startWithAppkey:@"5xxxxx3fd98c55858000e8d" launchOptions:launchOptions]; 

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)
    {
        
        
        // ios 8.0 之后,可以添加自定义categories
        
        //1.创建消息上面要添加的动作(按钮的形式显示出来)
        UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
        action1.identifier = @"action1_identifier";//按钮的标示
        action1.title=@"Accept";//按钮的标题
        action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
       
        UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  //第二按钮
        action2.identifier = @"action2_identifier";
        action2.title=@"Reject";
        action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
        action2.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
        action2.destructive = YES;
        
        UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
        categorys.identifier = @"category1";//这组动作的唯一标示,推送通知的时候也是根据这个来区分
        [categorys setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)];
        
        UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
                                                                                         categories:[NSSet setWithObject:categorys]];
        
        [UMessage registerRemoteNotificationAndUserNotificationSettings:userSettings];
        

    } else {
        //categories 必须为nil
        [UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
         |UIRemoteNotificationTypeSound
         |UIRemoteNotificationTypeAlert];
    }

//打开调试日志
    [UMessage setLogEnabled:YES];

[self.window makeKeyAndVisible];

 return YES;
}


注意这里的:

 categorys.identifier = @"category1";//这组动作的唯一标示,推送通知的时候也是根据这个来区分

这也就是,当我门在推送后台推送消息的时候,需要指明的标示,如果没有指明,那么也就不会注册通知的按键行为。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值