Created
May 7, 2020 20:55
-
-
Save navsing/d2cb092ae83d99f81e2eae07dbca4971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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