iOS8在通知中樞快速回複

來源:互聯網
上載者:User

標籤:

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在通知中樞快速回複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.