@@ -63,24 +63,14 @@ class RegionsListViewController: UIViewController {
63
63
64
64
let center = self . mapView. userLocation. coordinate
65
65
66
- UNUserNotificationCenter . current ( ) . requestAuthorization ( options: [ . alert, . sound] ) { granted, error in
66
+ UNUserNotificationCenter . current ( ) . requestAuthorization ( options: [ . alert, . sound] ) { [ self ] granted, error in
67
67
68
68
if let error = error {
69
- self . logger . log ( level : . error , " Error in requestAuthorization: \( error. localizedDescription) " )
69
+ self . handleError ( " Error in requestAuthorization: \( error. localizedDescription) " )
70
70
return
71
71
}
72
72
73
- guard CLLocationManager . isMonitoringAvailable ( for: CLCircularRegion . self) else {
74
- return
75
- }
76
- // Register the region.
77
- let region = CLCircularRegion ( center: center,
78
- radius: 10 ,
79
- identifier: identifier)
80
- region. notifyOnEntry = true
81
- region. notifyOnExit = true
82
-
83
- self . locationManager. startMonitoring ( for: region)
73
+ self . registerRegion ( identifier: identifier, center: center)
84
74
DispatchQueue . main. async {
85
75
self . updateMap ( )
86
76
}
@@ -90,7 +80,22 @@ class RegionsListViewController: UIViewController {
90
80
self . present ( alertController, animated: true )
91
81
}
92
82
93
- func updateMap( ) {
83
+ private func registerRegion( identifier: String , center: CLLocationCoordinate2D ) {
84
+ guard CLLocationManager . isMonitoringAvailable ( for: CLCircularRegion . self) else {
85
+ self . handleError ( " Circular Region Monitoring not available " )
86
+ return
87
+ }
88
+ // Register the region.
89
+ let region = CLCircularRegion ( center: center,
90
+ radius: 10 ,
91
+ identifier: identifier)
92
+ region. notifyOnEntry = true
93
+ region. notifyOnExit = true
94
+
95
+ self . locationManager. startMonitoring ( for: region)
96
+ }
97
+
98
+ private func updateMap( ) {
94
99
guard mapView != nil else {
95
100
return
96
101
}
@@ -116,12 +121,12 @@ class RegionsListViewController: UIViewController {
116
121
mapView. showAnnotations ( mapAnnotations, animated: true )
117
122
}
118
123
119
- func handleError ( _ error: Error ) {
124
+ private func handleError ( _ error: Error ) {
120
125
handleError ( error. localizedDescription)
121
126
}
122
127
123
- func handleError ( _ error: String ) {
124
- print ( error)
128
+ private func handleError ( _ error: String ) {
129
+ logger . error ( " \( error) " )
125
130
}
126
131
127
132
// MARK: - Navigation
@@ -180,7 +185,6 @@ extension RegionsListViewController: MKMapViewDelegate {
180
185
calloutAccessoryControlTapped control: UIControl ) {
181
186
self . performSegue ( withIdentifier: " RegionDetail " , sender: view. annotation)
182
187
}
183
-
184
188
}
185
189
186
190
// MARK: - CLLocationManagerDelegate
0 commit comments