Skip to content

Instantly share code, notes, and snippets.

@navsing
Created May 7, 2020 20:55
Show Gist options
  • Save navsing/d2cb092ae83d99f81e2eae07dbca4971 to your computer and use it in GitHub Desktop.
Save navsing/d2cb092ae83d99f81e2eae07dbca4971 to your computer and use it in GitHub Desktop.
func scheduleNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
print("Success")
//To add badgeNumber
//UIApplication.shared.applicationIconBadgeNumber = badgeNumber (Integer Value)
} else if let error = error {
print(error.localizedDescription)
}
}
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "Daily Notification"
content.body = "Daily Notification is Ready"
content.sound = UNNotificationSound.default
var dateComponents = DateComponents()
dateComponents.hour = 11
dateComponents.minute = 59
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment