自定义推送显示按钮

在iOS8以后,推送消息不再只是简单地点击打开客户端,对推送消息下拉时还可以执行预先设定好的操作,例如我们常用的QQ等下拉会有一个快捷回复的功能。接下来我们就介绍一下怎样用友盟Push的SDK实现这一功能:
第一步:集成友盟的PushSDK
第二步:编写策略代码

UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
    action1.identifier = @"action1_identifier";
    action1.title=@"增加";
    action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序

    UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  //第二按钮
    action2.identifier = @"action2_identifier";
    action2.title=@"修改";
    action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
    action2.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
    action2.destructive = YES;

    UIMutableUserNotificationCategory *actionCategory1 = [[UIMutableUserNotificationCategory alloc] init];
    actionCategory1.identifier = @"category1";//这组动作的唯一标示
    [actionCategory1 setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)];



    UIMutableUserNotificationAction *action3 = [[UIMutableUserNotificationAction alloc] init];
    action3.identifier = @"action3_identifier";
    action3.title=@"删除";
    action3.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序

    UIMutableUserNotificationAction *action4 = [[UIMutableUserNotificationAction alloc] init];  //第二按钮
    action4.identifier = @"action4_identifier";
    action4.title=@"重置";
    action4.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
    action4.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
    action4.destructive = YES;

    UIMutableUserNotificationCategory *actionCategory2 = [[UIMutableUserNotificationCategory alloc] init];
    actionCategory2.identifier = @"category2";//这组动作的唯一标示
    [actionCategory2 setActions:@[action3,action4] forContext:(UIUserNotificationActionContextDefault)];

    NSSet *categories = [NSSet setWithObjects:actionCategory1,actionCategory2, nil];

这段代码写了两个策略,每个策略有两个方法。
第三步:调用友盟的自定义注册方法

[UMessage registerForRemoteNotifications:categories];

第四步:添加通知接收代码,并运行
在didReceiveRemoteNotification中添加

[UMessage didReceiveRemoteNotification:userInfo];

第五步:友盟Push的后台添加推送策略
自定义推送显示按钮_第1张图片

你可能感兴趣的:(iOS)