- 本次iOS 8在推送方面最大的变化就是修改了推送的注册接口,在原本的推送type的基础上,增加了一个categories参数,这个参数的目的是用来注册一组和通知关联起来的button的事件。
- 这个categories由一系列的
UIUserNotificationCatego
ry组成。每个UIUserNotificationCatego ry对象包含你的app用来响应本地或者远程通知的信息。每一个对象的title作为通知上每一个button的title展示给用户。当用户点击了某一个button,系统将会调用应用内的回调函数(application:handleActionWithIdentifi er:forRemoteNotification:completionHandler:或者application:handleActionWithIdentifi er:forLocalNotification:completionHandler:。 - 推送接口的推送type由ios7和之前的UIRemoteNotificationType
类型,更改为UIUserNotificationType类型。
客户端设置
使用UIUserNotificationCatego ry
if
([[UIDevice currentDevice].systemVersion floatValue] >= 8.0){
NSMutableSet *categories = [NSMutableSet set];
UIMutableUserNotificatio
category.identifier = @
"identifier"
;
UIMutableUserNotificatio
action.identifier = @
"test2"
;
action.title = @
"test"
;
action.activationMode =UIUserNotificationActiva
action.authenticationRequired = YES;
//YES显示为红色,NO显示为蓝色
action.destructive = NO;
NSArray *actions = @[ action ];
[category setActions:actionsforContext:UIUserNotificationAction
[categories addObject:category];
}
|
使用UIUserNotificationType
if
([[UIDevice currentDevice].systemVersion floatValue] >=
8.0
){
[APServiceregisterForRemoteNotific
}
else
{
[APServiceregisterForRemoteNotific
}
|
使用回调函数
// 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 handleActionWithIdentifi
completionHandler:(
void
(^)())completionHandler {
}
|
服务端设置
服务端payload格式:aps增加category字段,当该字段与客户端UIMutableUserNotificatio
payload example:
{
"aps"
:{
"alert"
:
"example"
,
"sound"
:
"default"
,
"badge"
:
1
,
"category"
:
"identifier"
}}
|