Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Last active August 29, 2019 15:23
Show Gist options
  • Select an option

  • Save camiloibarrayepes/6dfb35396d69d8cc30648062bfc6a97d to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/6dfb35396d69d8cc30648062bfc6a97d to your computer and use it in GitHub Desktop.
//
// LocalNotificationsController.swift
//
import Foundation
import UserNotifications
class LocalNotificationsController {
init() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { (success, error) in
self.addNotifications()
}
}
func addNotifications() {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Realizaste algún movimiento bancario hoy?"
content.body = "Recuerda registrar tus gastos"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: 35.0,
repeats: false
)
let request = UNNotificationRequest(
identifier: "inteenseconds",
content: content,
trigger: trigger
)
center.add(request) { (error) in
guard let error = error else { return }
print(error.localizedDescription)
}
}
}
//Example Notification every day at especific time
var date = DateComponents()
date.hour = 20
date.minute = 00
date.timeZone = .current
let trigger =
UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment