Skip to content

Instantly share code, notes, and snippets.

@MaatheusGois
Last active July 4, 2019 10:03
Show Gist options
  • Select an option

  • Save MaatheusGois/fce3f0398c91b973d539cf779b662eb2 to your computer and use it in GitHub Desktop.

Select an option

Save MaatheusGois/fce3f0398c91b973d539cf779b662eb2 to your computer and use it in GitHub Desktop.
extension AppDelegate: UNUserNotificationCenterDelegate {
func enviarNotificacao(_ titulo:String, _ subtitulo:String, _ mensagem:String,
_ identificador:String, _ tempo:TimeInterval) {
//Essa instancia de classe é necessária para criar o corpo da notificação
let contexto = UNMutableNotificationContent()
//Criando corpo da notificação
contexto.title = titulo
contexto.subtitle = subtitulo
contexto.body = mensagem
contexto.sound = UNNotificationSound.default
//Badge é a o alerta vermelho que fica no icone do aplicativo
//quando há notificações e ela pode ser incrementada
contexto.badge = 1
contexto.categoryIdentifier = identificador
//Criando a requisição
let gatilho = UNTimeIntervalNotificationTrigger(timeInterval: tempo,
repeats: false)
let requisicao = UNNotificationRequest(identifier: identificador,
content: contexto, trigger: gatilho)
//Adicionando a requisição ao nosso centro de notificações
centroDeNotificacao.add(requisicao) { (error) in
if let error = error {
print("Deu ruim: \(error.localizedDescription)")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment