Created
April 20, 2018 12:35
-
-
Save mlcollard/f9c590eb56ed64196fcb60aabadec8f2 to your computer and use it in GitHub Desktop.
iOS: Notifications
This file contains 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
// TODO: import UserNotifications | |
// Create the notification content | |
let content = UNMutableNotificationContent() | |
content.title = "Hi" | |
content.body = "Hello" | |
print(#function, #line) | |
// Configure the notification trigger for 3 seconds | |
var dateInfo = DateComponents() | |
dateInfo.hour = Calendar.current.component(.hour, from: Date()) | |
dateInfo.minute = Calendar.current.component(.minute, from: Date()) + 1 | |
let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: false) | |
print(#function, #line) | |
// Create the notification request object. | |
let request = UNNotificationRequest(identifier: "MorningAlarm", content: content, trigger: trigger) | |
print(#function, #line) | |
// Schedule the request. | |
let center = UNUserNotificationCenter.current() | |
center.add(request) { | |
error in | |
if let error = error { | |
print(error.localizedDescription) | |
} | |
print(#function, #line) | |
} | |
print(#function, #line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment