7.IOS 8 UIUserNotificationSettings 推送

  1. 本次iOS 8在推送方面最大的变化就是修改了推送的注册接口,在原本的推送type的基础上,增加了一个categories参数,这个参数的目的是用来注册一组和通知关联起来的button的事件。
  2. 这个categories由一系列的 UIUserNotificationCategory组成。每个UIUserNotificationCategory对象包含你的app用来响应本地或者远程通知的信息。每一个对象的title作为通知上每一个button的title展示给用户。当用户点击了某一个button,系统将会调用应用内的回调函数(application:handleActionWithIdentifier:forRemoteNotification:completionHandler:或者application:handleActionWithIdentifier:forLocalNotification:completionHandler:
  3. 推送接口的推送type由ios7和之前的UIRemoteNotificationType类型,更改为UIUserNotificationType类型。

客户端设置

使用UIUserNotificationCategory

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0){
NSMutableSet *categories = [NSMutableSet set];
UIMutableUserNotificationCategory *category =[[UIMutableUserNotificationCategory alloc] init];
category.identifier = @ "identifier" ;
UIMutableUserNotificationAction *action =[[UIMutableUserNotificationAction alloc] init];
action.identifier = @ "test2" ;
action.title = @ "test" ;
action.activationMode =UIUserNotificationActivationModeBackground;
action.authenticationRequired = YES;
//YES显示为红色,NO显示为蓝色
action.destructive = NO;
NSArray *actions = @[ action ];
[category setActions:actionsforContext:UIUserNotificationActionContextMinimal];
[categories addObject:category];
}

使用UIUserNotificationType

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0 ){
[APServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)                     categories:categories];
} else {
[APServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)                     categories:nil];
}

 

使用回调函数

// Called when your app has been activated by the user selecting anaction from
// a remote notification.
// A nil action identifier indicates the defaultaction.
// You should call the completion handler as soon as you'vefinished handling
// the action.
- ( void )application:(UIApplication*)application handleActionWithIdentifier:(NSString *)identifierforRemoteNotification:(NSDictionary *)userInfo
   completionHandler:( void (^)())completionHandler {
}

 

服务端设置

服务端payload格式:aps增加category字段,当该字段与客户端UIMutableUserNotificationCategory的identifier匹配时,触发设定的action和button显示。

payload example:
{ "aps" :{ "alert" : "example" , "sound" : "default" , "badge" : 1 , "category" : "identifier" }}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值