By default from notification we open the first ViewController of the Mail.Storyboard. Is it possible to open another Storyboard? I tried few solutions already but don't works for me. Whole code is below. Let me know please if need more information. Thanks a lot.
import UIKit
import UserNotifications
class Notifications: UIViewController, UNUserNotificationCenterDelegate {
@IBOutlet weak var scheludeMeal: UIButton!
@IBOutlet weak var firstDatePicker: UIDatePicker!
...
var savedFirstNotification: Date? {
get {
return UserDefaults.standard.object(forKey: "firstMealTime") as? Date
}
set {
UserDefaults.standard.set(newValue, forKey: "firstMealTime")
}
}
...
}
override func viewDidLoad() {
super.viewDidLoad()
turnOnNotification.isHidden = true
if let savedFirstNotification = savedFirstNotification {
firstDatePicker.date = savedFirstNotification
}
...
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("Yes!")
} else {
print("No...?")
}
}
}
...
@IBAction func scheludeButton(_ sender: Any) {
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "Ttile"
content.body = "Description of notification :)"
content.sound = UNNotificationSound.default
let firstMealComponent = firstDatePicker.calendar.dateComponents([.hour, .minute], from: firstDatePicker.date)
let trigger = UNCalendarNotificationTrigger(dateMatching: firstMealComponent, repeats: true)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
savedFirstNotification = firstDatePicker.date
...
}
}