7.IOS 8 UIUserNotificationSettings 推送
2015-09-01 16:56
525 查看
本次iOS 8在推送方面最大的变化就是修改了推送的注册接口,在原本的推送type的基础上,增加了一个categories参数,这个参数的目的是用来注册一组和通知关联起来的button的事件。这个categories由一系列的
服务端payload格式:aps增加category字段,当该字段与客户端UIMutableUserNotificationCategory的identifier匹配时,触发设定的action和button显示。
UIUserNotificationCategory组成。每个UIUserNotificationCategory对象包含你的app用来响应本地或者远程通知的信息。每一个对象的title作为通知上每一个button的title展示给用户。当用户点击了某一个button,系统将会调用应用内的回调函数(application:handleActionWithIdentifier:forRemoteNotification:completionHandler:或者application:handleActionWithIdentifier:forLocalNotification:completionHandler:。推送接口的推送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" }} |
相关文章推荐
- 6.UIActionSheet的最后一项点击失效
- iOS UIFont 字体名字大全
- Android Stuido中SVN的设置
- solr query
- **ERROR: Ninja build tool not found.
- UIResponder - 1
- 短语out of the blue
- 关于squirrel的那些事
- deque双向队列
- uva1584 - Circular Sequence
- values v11 v14
- iOS开发-综合UI案例-彩票
- android retrofit @Query用法
- 8.10.3 The MySQL Query Cache
- 被曝红米Note 2屏幕和摄像头偷梁换柱后,小米换图,删帖,发声明
- div设置contentEditable="true"作为文本编辑器,定位光标解决办法
- LeetCode Distinct Subsequences DP
- UILabel圆角、边框、宽度自适应
- QuickServer自学笔记(一)
- *** Assertion failure in -[CompensaCommentView _dequeueReusableViewOfType:withIdentifier:],