forked from bruom/LocalNotificationsBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseViewController.swift
More file actions
47 lines (36 loc) · 1.64 KB
/
Copy pathBaseViewController.swift
File metadata and controls
47 lines (36 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// ViewController.swift
// LocalNotificationBase
//
// Created by Bruno Omella Mainieri on 12/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//
import UIKit
import UserNotifications
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func remindButton(_ sender: Any) {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Lembre-se", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "Você se lembrou", arguments: nil)
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "5seconds", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request) { (error : Error?) in
if let error = error {
print(error.localizedDescription)
}
}
} else {
print("Impossível mandar notificação - permissão negada")
}
}
}
}