@@ -16,10 +16,12 @@ class RegionsListViewController: UIViewController {
16
16
private var logger = Logger ( )
17
17
18
18
@IBOutlet var mapView : MKMapView !
19
+ @IBOutlet var addButton : UIBarButtonItem !
19
20
20
21
override func viewDidLoad( ) {
21
22
super. viewDidLoad ( )
22
23
24
+ addButton. accessibilityLabel = NSLocalizedString ( " Add Monitored Region at current location " , comment: " Accessibilty label for add button " )
23
25
locationManager. delegate = self
24
26
25
27
registerMapAnnotationViews ( )
@@ -31,7 +33,11 @@ class RegionsListViewController: UIViewController {
31
33
self . mapView. showsUserLocation = true
32
34
mapView. setCenter ( mapView. userLocation. coordinate, animated: true )
33
35
default :
34
- let alert = UIAlertController ( title: " No authorization " , message: " This app requires the location services to be authorised " , preferredStyle: . alert)
36
+ let alert = UIAlertController ( title: NSLocalizedString ( " No authorization " ,
37
+ comment: " Alert: Authorization to Localization denied " ) ,
38
+ message: NSLocalizedString ( " This app requires the location services to be authorised " ,
39
+ comment: " Alert: Authorization to Localization denied " ) ,
40
+ preferredStyle: . alert)
35
41
self . present ( alert, animated: true )
36
42
}
37
43
}
@@ -47,14 +53,20 @@ class RegionsListViewController: UIViewController {
47
53
}
48
54
49
55
@IBAction func addRegionAction( ) {
50
- let alertController = UIAlertController ( title: " New Region " , message: " Please enter a name " , preferredStyle: . alert)
56
+ let alertController = UIAlertController ( title: NSLocalizedString ( " New Region " ,
57
+ comment: " New Region Alert " ) ,
58
+ message: NSLocalizedString ( " Please enter a name " ,
59
+ comment: " New Region Alert " ) ,
60
+ preferredStyle: . alert)
51
61
alertController. addTextField ( )
52
- alertController. addAction ( UIAlertAction ( title: " Cancel " ,
62
+ alertController. addAction ( UIAlertAction ( title: NSLocalizedString ( " Cancel " ,
63
+ comment: " New Region Alert " ) ,
53
64
style: . cancel,
54
65
handler: { _ in
55
66
return
56
67
} ) )
57
- alertController. addAction ( UIAlertAction ( title: " OK " ,
68
+ alertController. addAction ( UIAlertAction ( title: NSLocalizedString ( " OK " ,
69
+ comment: " New Region Alert " ) ,
58
70
style: . default,
59
71
handler: { _ in
60
72
guard let identifier = alertController. textFields? . first? . text else {
@@ -121,11 +133,11 @@ class RegionsListViewController: UIViewController {
121
133
mapView. showAnnotations ( mapAnnotations, animated: true )
122
134
}
123
135
124
- private func handleError ( _ error: Error ) {
136
+ internal func handleError ( _ error: Error ) {
125
137
handleError ( error. localizedDescription)
126
138
}
127
139
128
- private func handleError ( _ error: String ) {
140
+ internal func handleError ( _ error: String ) {
129
141
logger. error ( " \( error) " )
130
142
}
131
143
@@ -136,8 +148,7 @@ class RegionsListViewController: UIViewController {
136
148
137
149
if let destination = segue. destination as? RegionViewController {
138
150
guard let annotation = sender as? MKAnnotation else {
139
- let logger = Logger ( )
140
- logger. log ( level: . error, " Sender was not MKAnnotation " )
151
+ self . handleError ( " Sender was not MKAnnotation " )
141
152
return
142
153
}
143
154
guard let identifier = annotation. title else {
@@ -186,77 +197,3 @@ extension RegionsListViewController: MKMapViewDelegate {
186
197
self . performSegue ( withIdentifier: " RegionDetail " , sender: view. annotation)
187
198
}
188
199
}
189
-
190
- // MARK: - CLLocationManagerDelegate
191
-
192
- extension RegionsListViewController : CLLocationManagerDelegate {
193
- func locationManager( _ manager: CLLocationManager , didEnterRegion region: CLRegion ) {
194
- let date = Date ( )
195
- let content = UNMutableNotificationContent ( )
196
- content. title = " Region Entered "
197
- content. body = " \( region. identifier) \( date) "
198
-
199
- let eventRecord = EventRecord ( event: . ENTER,
200
- identifier: region. identifier,
201
- date: date)
202
- do {
203
- try storage. store ( eventRecord)
204
- }
205
- catch let error {
206
- self . handleError ( error)
207
- }
208
- let request = UNNotificationRequest ( identifier: region. identifier,
209
- content: content,
210
- trigger: nil )
211
- UNUserNotificationCenter . current ( ) . add ( request)
212
- }
213
-
214
- func locationManager( _ manager: CLLocationManager , didExitRegion region: CLRegion ) {
215
- let content = UNMutableNotificationContent ( )
216
- content. title = " Region Exited "
217
- content. body = " \( region. identifier) \( Date ( ) ) "
218
-
219
- let eventRecord = EventRecord ( event: . EXIT,
220
- identifier: region. identifier,
221
- date: Date ( ) )
222
- do {
223
- try storage. store ( eventRecord)
224
- }
225
- catch let error {
226
- self . handleError ( error)
227
- }
228
- let request = UNNotificationRequest ( identifier: region. identifier,
229
- content: content,
230
- trigger: nil )
231
- UNUserNotificationCenter . current ( ) . add ( request)
232
- }
233
-
234
- func locationManager( _ manager: CLLocationManager ,
235
- monitoringDidFailFor region: CLRegion ? ,
236
- withError error: Error
237
- ) {
238
- self . handleError ( error)
239
- }
240
-
241
- func locationManager( _ manager: CLLocationManager ,
242
- didChangeAuthorization status: CLAuthorizationStatus ) {
243
- switch status {
244
- case . restricted, . denied:
245
- // Disable your app's location features
246
- self . handleError ( " Warning: Location restricted or denied " )
247
-
248
- case . authorizedWhenInUse:
249
- // Enable your app's location features.
250
- self . handleError ( " Warning: Location InUse Only " )
251
-
252
- case . authorizedAlways:
253
- self . mapView. showsUserLocation = true
254
- // Enable or prepare your app's location features that can run any time.
255
-
256
- case . notDetermined:
257
- self . handleError ( " Warning: Location Not Determined " )
258
- default :
259
- self . handleError ( " Warning: Switch fell through " )
260
- }
261
- }
262
- }
0 commit comments