码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8在通知中心快速回复

时间:2016-08-10 12:42:18      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

1 在application:didFinishLaunchingWithOptions:中注册通知时:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
     //创建消息上添加的动作,以按钮的形式显示 let acceptAction
= UIMutableUserNotificationAction() acceptAction.title = "接受" acceptAction.identifier = "acceptIdentifier" acceptAction.activationMode = UIUserNotificationActivationMode.Foreground let rejectAction = UIMutableUserNotificationAction() rejectAction.title = "拒绝" rejectAction.identifier = "rejectIdentifier" rejectAction.activationMode = UIUserNotificationActivationMode.Background //需要解锁才能处理,如果activationMode = UIUserNotificationActivationMode.Background,则这个属性忽略 rejectAction.authenticationRequired = true rejectAction.destructive = true //创建动作按钮的类别集合 let category = UIMutableUserNotificationCategory() category.identifier = "alert" category.setActions([acceptAction, rejectAction], forContext: UIUserNotificationActionContext.Minimal)

         //创建UIUserNotificationSettings,并设置消息的显示类型

      let notifSetting = UIUserNotificationSettings(forTypes: .Badge , categories: NSSet(object: category) as? Set<UIUserNotificationCategory>)

 

        //注册本地通知

         application.registerUserNotificationSettings(notifSetting)

     return true
 }

2 在使用Push的时候需要在数据包中加入特定的Category字段(字段内容需要前后端定义为一致),终端接收到到后,就能展示上述代码对应Category设置的按钮,和响应按钮事件。

 

iOS8在通知中心快速回复

标签:

原文地址:http://www.cnblogs.com/muzijie/p/5756097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!