###前提・実現したいこと
ローカル通知にボタンを配置したい。
この図のようなものをつくりたい。
(参照 http://dev.classmethod.jp/references/ios8-notification-action/)
ロック画面でスライドした時に現れるボタンの編集がしたい。
###発生している問題・エラーメッセージ
現状ですと上記のようにロック画面でのアクションがclearのみになっている。
ここに現れるボタンの編集がしたい。
(参照サイト http://qiita.com/mshrwtnb/items/3135e931eedc97479bb5)
言語:swift
User Notifications Frameworkを使って実装したいが、やり方がわからない。
###試したこと
AppDelegate.swift
swift
1func applicationDidEnterBackground(_ application: UIApplication) { 2 3 enum ActionIdentifier: String { 4 case attend 5 case absent 6 } 7 8 let attend = UNNotificationAction(identifier: ActionIdentifier.attend.rawValue, 9 title: "出席", options: []) 10 11 let absent = UNNotificationAction(identifier: ActionIdentifier.absent.rawValue, 12 title: "欠席", 13 options: []) 14 15 16 let category = UNNotificationCategory(identifier: "message", actions: [attend, absent], intentIdentifiers: [], options: []) 17 18 19 UNUserNotificationCenter.current().setNotificationCategories([category]) 20 21 22 23 let content = UNMutableNotificationContent() 24 content.title = "出席確認" 25 content.body = "今日のイベントに参加しますか?" 26 content.sound = UNNotificationSound.default() 27 28 // categoryIdentifierを設定 29 content.categoryIdentifier = "message" 30 31 // 5秒後 32 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) 33 let request = UNNotificationRequest(identifier: "FiveSecond", 34 content: content, 35 trigger: trigger) 36 37 UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) 38 39 @available(iOS 10.0, *) 40 func userNotificationCenter(_ center: UNUserNotificationCenter, 41 didReceive response: UNNotificationResponse, 42 withCompletionHandler completionHandler: () -> Void) { 43 44 switch response.actionIdentifier { 45 case ActionIdentifier.attend.rawValue: 46 debugPrint("出席します") 47 case ActionIdentifier.absent.rawValue: 48 debugPrint("欠席します") 49 default: 50 () 51 } 52 53 completionHandler() 54 } 55 56 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/22 08:20
2016/10/22 08:41 編集