This repository was archived by the owner on Feb 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocationCore.swift
More file actions
142 lines (114 loc) · 3.94 KB
/
LocationCore.swift
File metadata and controls
142 lines (114 loc) · 3.94 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// LocationCore.swift
// SurpriseMe
//
// Created by Gleb Karpushkin on 15/09/2016.
// Copyright © 2016 SurpriseMe. All rights reserved.
//
import Foundation
import CoreLocation
public protocol LocationProtocol {
var manager: CLLocationManager { get }
var desiredAccuracy: CLLocationAccuracy { get set }
var distanceFilter: CLLocationDistance { get set }
var pausesLocationUpdates: Bool { get set }
var monitoringAlavialbe: Bool {get set}
func startUpdating()
func stopUpdating()
func monitorNewRegion(_ region: CLCircularRegion)
func stopMonitorRegion(_ region: CLCircularRegion)
func getLocationAccuracy() -> String
init()
}
fileprivate class LocationManagerDelegate: NSObject, CLLocationManagerDelegate {
deinit {
print("Location Core Deinitialized")
}
internal func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
}
internal func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
NSLog("\(error)")
}
internal func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {
NSLog("\(error)")
}
internal func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
}
internal func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
switch state {
case .inside:
break
case .outside:
break
default:
break
}
}
internal func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .authorizedAlways:
break
case .authorizedWhenInUse:
break
case .denied :
break
case .notDetermined:
break
case .restricted:
break
}
}
}
struct Location: LocationProtocol {
public var desiredAccuracy: CLLocationAccuracy
public var distanceFilter: CLLocationDistance
public var pausesLocationUpdates: Bool
public var monitoringAlavialbe: Bool
public static var core: LocationProtocol = Location()
public var manager = CLLocationManager()
fileprivate var managerDelegate = LocationManagerDelegate()
init() {
self.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.distanceFilter = kCLDistanceFilterNone
self.pausesLocationUpdates = false
self.monitoringAlavialbe = CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self)
manager.delegate = managerDelegate
manager.allowsBackgroundLocationUpdates = true
manager.requestAlwaysAuthorization()
}
public func startUpdating() {
self.manager.startUpdatingLocation()
}
public func stopUpdating() {
self.manager.stopUpdatingLocation()
}
public func monitorNewRegion(_ region: CLCircularRegion) {
region.notifyOnEntry = true
self.manager.startMonitoring(for: region)
}
public func stopMonitorRegion(_ region: CLCircularRegion) {
self.manager.startMonitoring(for: region)
}
public func getLocationAccuracy() -> String {
if (self.manager.location!.horizontalAccuracy < 0)
{
print("No Signal")
return "No Signal".localized
}
else if (self.manager.location!.horizontalAccuracy > 163)
{
print("Poor Signal")
return "Poor".localized
}
else if (self.manager.location!.horizontalAccuracy > 48)
{
print("Average Signal")
return "Average".localized
}
else
{
print("Full Signal")
return "Full".localized
}
}
}