1
我想在應用程序收到操作響應時訪問AppDelegate.swift中的應用程序數據。我試圖使用在AppDelegate中獲取本地通知的正文或標識符Swift
方法,但我無法找到數據,因爲我無法獲取通知的標識符及其正文。有人能幫我解決嗎?非常感謝你們。
更多的代碼:
//Setting content of the notification
let content = UNMutableNotificationContent()
content.title = "Scheduled Task"
content.body = taskDescriptionTextField.text!
content.badge = 1
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "alertCategory"
//Setting time for notification trigger
let date = datePicker.date
let dateCompenents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateCompenents, repeats: false)
//Adding Request
let request = UNNotificationRequest(identifier: taskDescriptionTextField.text!, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
也許你錯過了一些東西,而實施它。請再提一些代碼。 –
thx幫助。我不知道如何通過調用方法didReceive響應來獲取通知的標識符或主體內容...有什麼辦法可以將這些數據從另一個ViewController發送到AppDelegate?更多來自下面的ViewController的代碼。 –
可能會研究這個問題: - http://www.appcoda.com/local-notifications-ios8/ 它涵蓋了所有基本的東西。 –