「クイック返信」や「キャンセル」のような2つのアクションボタンを使用して通知を作成しようとしていますが、これに関するコード例は見つかりません。誰かがSwift 3でこれを行う方法を説明することができます。Swiftローカルプッシュ通知アクションビュー
0
A
答えて
0
あなたが探しているものの正確な例を与えることは難しいです。アクションのある即時実行UNUserNotificationCenter
の実装です。
import UserNotifications
セットアップ
private let categoryID = "Category"
IDが一定のカテゴリを定義し、通知
をトリガするためUNUserNotificationCenter
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
// Configure User Notification Center
UNUserNotificationCenter.current().delegate = self
// Define Actions
let actionShowSomething = UNNotificationAction(identifier: "ShowSomething", title: "Show Something", options: [])
// Define Category
let category = UNNotificationCategory(identifier: categoryID, actions: [actionShowSomething], intentIdentifiers: [], options: [])
// Register Category
UNUserNotificationCenter.current().setNotificationCategories([category])
}
例のイベントを登録
// MARK: - Actions @IBAction func sheduleNotification(sender: UIButton) { // Request Notification Settings UNUserNotificationCenter.current().getNotificationSettings { (notificationSettings) in switch notificationSettings.authorizationStatus { case .notDetermined: self.requestAuthorization(completionHandler: { (success) in guard success else { return } // Schedule Local Notification self.scheduleLocalNotification() }) case .authorized: // Schedule Local Notification self.scheduleLocalNotification() case .denied: print("Application Not Allowed to Display Notifications") } } }
sheduleNotification
実装
// MARK: - Methods
private func scheduleLocalNotification() {
// Create Notification Content
let notificationContent = UNMutableNotificationContent()
// Configure Notification Content
notificationContent.title = "Title"
notificationContent.subtitle = "Subtitle"
notificationContent.body = "Body"
// Set Category Identifier
notificationContent.categoryIdentifier = categoryID
// Add Trigger
let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)
// Create Notification Request
let notificationRequest = UNNotificationRequest(identifier: "cocoacasts_local_notification", content: notificationContent, trigger: notificationTrigger)
// Add Request to User Notification Center
UNUserNotificationCenter.current().add(notificationRequest) { (error) in
if let error = error {
print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
}
}
}
ハンドルユーザ通知許可
private func requestAuthorization(completionHandler: @escaping (_ success: Bool) ->()) {
// Request Authorization
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (success, error) in
if let error = error {
print("Request Authorization Failed (\(error), \(error.localizedDescription))")
}
completionHandler(success)
}
}
UnUserNotificationDelegate
実装
結果
0
あなたはUIMutableUserNotificationAction
することによって、これを達成することができます: -
1)https://nrj.io/simple-interactive-notifications-in-ios-8/
2)http://www.imore.com/interactive-notifications-ios-8-explained
関連する問題
- 1. Xamarinフォームによるローカルプッシュ通知
- 2. 反応ネイティブのローカルプッシュ通知の再発
- 3. LGSideMenuController:複数のローカルプッシュ通知の登録は
- 4. コードバスアプリケーションでローカルプッシュ通知を実装する方法
- 5. iOSローカルプッシュ通知がデバイスを復帰させない
- 6. iOSローカルプッシュ通知は、ミュート/サイレントモードをオーバーライドします
- 7. Swiftカスタムデータプッシュ通知
- 8. iOSアプリのEmoji - 通知/通知 - Xcode/Swift
- 9. プッシュ通知swift 3
- 10. ユーザー通知Swift 3
- 11. プッシュ通知didReceiveRemoteNotification swift
- 12. ローカル通知swift 3
- 13. リモート通知の代わりにローカルプッシュ通知で可変コンテンツを使用できますか?
- 14. ローカルプッシュ通知を処理することは、アプリは、iOS 10では
- 15. Swift iOS 10のプッシュ通知
- 16. iOS Swift 3バンドル通知
- 17. iOSのAzureプッシュ通知Swift
- 18. Swift FIRMessagingプッシュ通知トークンリセット
- 19. 毎日通知Swift 3
- 20. Swiftで通知コントローラに通知データを渡す方法
- 21. SwiftでのNSWorkspace通知のリッスン4
- 22. Swift - BadUnumberIconのUNUser通知チェックの変更
- 23. Swift 3のMicrosoft Azureリモート通知
- 24. Swiftの通知にifステートメントを追加
- 25. リモート通知のカスタムサウンドiOS 10、swift 3
- 26. AWSプッシュ通知フローとSDK for swift 3
- 27. 週3回のトリガー通知Swift 3
- 28. レルムファイングレイン通知Swift 3の構文
- 29. 動的ロケーションベースのローカル通知Swift iOS
- 30. Firebaseプッシュ通知 - XCode 8.0/Swift 3.0/ios 10.0
iOS 10を使用しようとしていますか? –
はい@SalmanGhumsani –