forked from bruom/LocalNotificationsBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBronzeNotificationTableViewController.swift
More file actions
123 lines (91 loc) · 3.75 KB
/
Copy pathBronzeNotificationTableViewController.swift
File metadata and controls
123 lines (91 loc) · 3.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// BronzeNotificationTableViewController.swift
// LocalNotificationBase
//
// Created by Julia Santos on 13/06/19.
// Copyright © 2019 Bruno Omella Mainieri. All rights reserved.
//
import UIKit
import UserNotifications
class BronzeNotificationTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerTimeData.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerTimeData[row]
}
@IBOutlet weak var titulo: UITextField!
@IBOutlet weak var corpo: UITextField!
@IBOutlet weak var labelTempo: UILabel!
@IBOutlet weak var picker: UIPickerView!
@IBOutlet weak var labelSom: UILabel!
@IBOutlet weak var labelBadge: UILabel!
@IBOutlet weak var segmentedControlBadge: UISwitch!
@IBOutlet weak var segmentedControl: UISwitch!
@IBAction func button(_ sender: Any) {
let content = UNMutableNotificationContent()
if segmentedControlBadge.isOn {
content.badge = true
}else{
content.badge = false
}
if segmentedControl.isOn {
// let content = UNMutableNotificationContent()
content.sound = UNNotificationSound.default
}
else{
// let content = UNMutableNotificationContent()
content.sound = nil
}
if let texto = self.titulo.text {
content.title = NSString.localizedUserNotificationString(forKey: texto, arguments: nil)
}
if let bodyy = self.corpo.text{
content.body = NSString.localizedUserNotificationString(forKey: bodyy, arguments: nil)
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(self.picker.selectedRow(inComponent: 0)), repeats: false)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
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")
}
}
}
var pickerTimeData: [String] = [String]()
var celulaEstaGrande:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
pickerTimeData = ["1", "2", "3", "4", "5", "6", "7", "8"]
self.picker.delegate = self
self.picker.dataSource = self
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 0 {
if celulaEstaGrande {
return 250
}
else {
return 44
}
}
return 44
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 0{
celulaEstaGrande = !celulaEstaGrande
tableView.beginUpdates()
tableView.endUpdates()
}
}
}