Last active
July 4, 2019 10:03
-
-
Save MaatheusGois/fce3f0398c91b973d539cf779b662eb2 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
| 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