Created
December 27, 2018 10:55
-
-
Save JayachandraA/f066755aa48954cf3fc2e24b0add9967 to your computer and use it in GitHub Desktop.
The following snippet of code provides how to display a locations to the user. In order to display the notification first of all you are required to request the user permissions to send your local notification.
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
// request for user permisstions | |
UNUserNotificationCenter.current().requestAuthorization(options: [UNAuthorizationOptions.badge, UNAuthorizationOptions.sound, UNAuthorizationOptions.alert]) { (yes, error) in | |
} | |
// fill up with the following objects | |
let context = UNMutableNotificationContent() | |
context.badge = NSNumber(integerLiteral: UIApplication.shared.applicationIconBadgeNumber + 1) | |
context.title = "It is Gym time now" | |
context.body = "Now you have to wake up and go to Gym." | |
context.launchImageName = "icon" | |
//UNTimeIntervalNotificationTrigger, UNCalendarNotificationTrigger, UNLocationNotificationTrigger | |
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) | |
let localNotification = UNNotificationRequest(identifier: "alarm_notificatio_id", content: context, trigger: trigger) | |
// finally add your notification to the center | |
UNUserNotificationCenter.current().add(localNotification) { (error) in | |
print(error as Any) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment