@woosmap/react-native-plugin-geofencing 0.11.0-beta.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/ios/PluginGeofencing.swift +34 -3
- package/ios/WoosmapGeofenceService.swift +820 -705
- package/package.json +1 -1
- package/react-native-plugin-geofencing.podspec +2 -27
|
@@ -5,778 +5,893 @@
|
|
|
5
5
|
// Created by apple on 02/08/21.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
+
import CoreLocation
|
|
8
9
|
import Foundation
|
|
9
10
|
import UIKit
|
|
10
|
-
import CoreLocation
|
|
11
11
|
import WoosmapGeofencing
|
|
12
12
|
|
|
13
13
|
extension CLRegion {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return seperated[1]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return idFormat
|
|
23
|
-
}
|
|
14
|
+
var normalizeIdentifier: String {
|
|
15
|
+
let idFormat = self.identifier
|
|
16
|
+
if idFormat.contains("::") {
|
|
17
|
+
let seperated = idFormat.components(separatedBy: "@")
|
|
18
|
+
return seperated[1]
|
|
24
19
|
}
|
|
20
|
+
|
|
21
|
+
return idFormat
|
|
22
|
+
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
/// Geofence services
|
|
28
26
|
@objc(WoosmapGeofenceService) public class WoosmapGeofenceService: NSObject {
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
28
|
+
/// Share object for WoosmapGeofenceService
|
|
29
|
+
@objc static var shared: WoosmapGeofenceService? {
|
|
30
|
+
return _shared
|
|
31
|
+
}
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
defaults.set(newValue, forKey: "WoosmapGeofenceService.protectedregionslot")
|
|
58
|
-
}
|
|
33
|
+
private var _isServiceRunning: Bool = false
|
|
34
|
+
private static var _shared: WoosmapGeofenceService?
|
|
35
|
+
private var woosmapKey: String = ""
|
|
36
|
+
private var defaultProfile: String = ""
|
|
37
|
+
private var enableAirshipCallback: Bool = false
|
|
38
|
+
private let dataLocation = DataLocation()
|
|
39
|
+
private let dataPOI = DataPOI()
|
|
40
|
+
private let dataDistance = DataDistance()
|
|
41
|
+
private let dataRegion = DataRegion()
|
|
42
|
+
private let dataVisit = DataVisit()
|
|
43
|
+
private let airshipEvents = AirshipEvents()
|
|
44
|
+
private let marketingCloudEvents = MarketingCloudEvents()
|
|
45
|
+
private var sdkInstance: WoosmapGeofenceManager?
|
|
46
|
+
private var protectedRegionSlot: Int {
|
|
47
|
+
get {
|
|
48
|
+
let defaults = UserDefaults.standard
|
|
49
|
+
let protectedSlot = defaults.integer(
|
|
50
|
+
forKey: "WoosmapGeofenceService.protectedregionslot"
|
|
51
|
+
)
|
|
52
|
+
return protectedSlot
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
set {
|
|
68
|
-
let defaults = UserDefaults.standard
|
|
69
|
-
defaults.set(newValue, forKey: "WoosmapGeofenceService.poiradius")
|
|
70
|
-
}
|
|
54
|
+
set {
|
|
55
|
+
let defaults = UserDefaults.standard
|
|
56
|
+
defaults.set(
|
|
57
|
+
newValue,
|
|
58
|
+
forKey: "WoosmapGeofenceService.protectedregionslot"
|
|
59
|
+
)
|
|
71
60
|
}
|
|
61
|
+
}
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
WoosmapGeofenceManager.shared.setSearchAPIRequestEnable(enable: newValue)
|
|
80
|
-
|
|
81
|
-
}
|
|
63
|
+
private var defaultPOIRadius: String {
|
|
64
|
+
get {
|
|
65
|
+
let defaults = UserDefaults.standard
|
|
66
|
+
let defaultPOIRadius =
|
|
67
|
+
defaults.string(forKey: "WoosmapGeofenceService.poiradius") ?? ""
|
|
68
|
+
return defaultPOIRadius
|
|
82
69
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
get {
|
|
87
|
-
return WoosmapGeofenceManager.shared.getDistanceAPIRequestEnable()
|
|
88
|
-
}
|
|
89
|
-
set {
|
|
90
|
-
WoosmapGeofenceManager.shared.setDistanceAPIRequestEnable(enable: newValue)
|
|
91
|
-
|
|
92
|
-
}
|
|
70
|
+
set {
|
|
71
|
+
let defaults = UserDefaults.standard
|
|
72
|
+
defaults.set(newValue, forKey: "WoosmapGeofenceService.poiradius")
|
|
93
73
|
}
|
|
74
|
+
}
|
|
94
75
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
set {
|
|
101
|
-
WoosmapGeofenceManager.shared.setSearchAPICreationRegionEnable(enable: newValue)
|
|
102
|
-
|
|
103
|
-
}
|
|
76
|
+
/// Status of search api On/Off
|
|
77
|
+
@objc public var searchAPIRequestEnable: Bool {
|
|
78
|
+
get {
|
|
79
|
+
return self.sdkInstance?.getSearchAPIRequestEnable() ?? false
|
|
104
80
|
}
|
|
81
|
+
set {
|
|
82
|
+
self.sdkInstance?.setSearchAPIRequestEnable(enable: newValue)
|
|
105
83
|
|
|
106
|
-
/// Status of HighfrequencyLocation Mode. On/Off
|
|
107
|
-
@objc public var modeHighfrequencyLocation: Bool {
|
|
108
|
-
get {
|
|
109
|
-
return WoosmapGeofenceManager.shared.getModeHighfrequencyLocation()
|
|
110
|
-
}
|
|
111
|
-
set {
|
|
112
|
-
WoosmapGeofenceManager.shared.setModeHighfrequencyLocation(enable: newValue)
|
|
113
|
-
}
|
|
114
84
|
}
|
|
85
|
+
}
|
|
115
86
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
set {
|
|
122
|
-
WoosmapGeofenceManager.shared.setTrackingEnable(enable: newValue)
|
|
123
|
-
}
|
|
87
|
+
/// Status of distance api On/Off
|
|
88
|
+
@objc public var distanceAPIRequestEnable: Bool {
|
|
89
|
+
get {
|
|
90
|
+
return self.sdkInstance?.getDistanceAPIRequestEnable() ?? false
|
|
124
91
|
}
|
|
92
|
+
set {
|
|
93
|
+
self.sdkInstance?.setDistanceAPIRequestEnable(enable: newValue)
|
|
125
94
|
|
|
126
|
-
// MARK: Application events
|
|
127
|
-
|
|
128
|
-
/// This callback received when application become active
|
|
129
|
-
@objc func appDidBecomeActive() {
|
|
130
|
-
let status = CLLocationManager.authorizationStatus()
|
|
131
|
-
if status == .authorizedAlways || status == .authorizedWhenInUse {
|
|
132
|
-
DispatchQueue.main.async {
|
|
133
|
-
WoosmapGeofenceManager.shared.didBecomeActive()
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
95
|
}
|
|
96
|
+
}
|
|
137
97
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
WoosmapGeofenceManager.shared.startMonitoringInBackground()
|
|
143
|
-
WoosmapGeofenceManager.shared.getLocationService().stopUpdatingLocation()
|
|
144
|
-
}
|
|
145
|
-
}
|
|
98
|
+
/// status of CreationRegionEnable. On/Off
|
|
99
|
+
@objc public var searchAPICreationRegionEnable: Bool {
|
|
100
|
+
get {
|
|
101
|
+
return self.sdkInstance?.getSearchAPICreationRegionEnable() ?? false
|
|
146
102
|
}
|
|
103
|
+
set {
|
|
104
|
+
self.sdkInstance?.setSearchAPICreationRegionEnable(enable: newValue)
|
|
147
105
|
|
|
148
|
-
/// This callback received when application is terminated
|
|
149
|
-
@objc func appWillTerminate() {
|
|
150
|
-
WoosmapGeofenceManager.shared.setModeHighfrequencyLocation(enable: false)
|
|
151
|
-
}
|
|
152
|
-
// MARK: Init
|
|
153
|
-
|
|
154
|
-
/// Initialize woosGeofencing service with key saved in previous call
|
|
155
|
-
private override init() {
|
|
156
|
-
super.init()
|
|
157
|
-
let defaults = UserDefaults.standard
|
|
158
|
-
let woosmapKey = defaults.string(forKey: "WoosmapGeofenceService.woosmap") ?? ""
|
|
159
|
-
let defaultProfile = defaults.string(forKey: "WoosmapGeofenceService.profile") ?? ""
|
|
160
|
-
self.enableAirshipCallback = defaults.bool(forKey: "WoosmapGeofenceService.AirshipCallbackEnable")
|
|
161
|
-
self.woosmapKey = woosmapKey
|
|
162
|
-
self.defaultProfile = defaultProfile
|
|
163
|
-
|
|
164
|
-
defaults.register(defaults: ["TrackingEnable": true,
|
|
165
|
-
"ModeHighfrequencyLocation": false,
|
|
166
|
-
"SearchAPIEnable": true,
|
|
167
|
-
"DistanceAPIEnable": true,
|
|
168
|
-
"searchAPICreationRegionEnable": true,
|
|
169
|
-
"WoosmapGeofenceService.protectedregionslot":0])
|
|
170
|
-
|
|
171
|
-
self.activateGeofenceService()
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/// Initialize service with keys and profile
|
|
176
|
-
/// - Parameters:
|
|
177
|
-
/// - woosmapKey: key use for woosmap service
|
|
178
|
-
/// - configurationProfile: configuration profile
|
|
179
|
-
/// - airshipEnable: To enable airship callback
|
|
180
|
-
private init(_ woosmapKey: String, _ configurationProfile: String, _ airshipEnable: Bool = false, _ protectedregionslot: Int = -1) {
|
|
181
|
-
super.init()
|
|
182
|
-
let defaults = UserDefaults.standard
|
|
183
|
-
if(woosmapKey == ""){
|
|
184
|
-
let lastSaved = defaults.string(forKey: "WoosmapGeofenceService.woosmap") ?? ""
|
|
185
|
-
self.woosmapKey = lastSaved
|
|
186
|
-
}
|
|
187
|
-
else{
|
|
188
|
-
self.woosmapKey = woosmapKey
|
|
189
|
-
}
|
|
190
|
-
if(configurationProfile == ""){
|
|
191
|
-
let lastSaved = defaults.string(forKey: "WoosmapGeofenceService.profile") ?? ""
|
|
192
|
-
self.defaultProfile = lastSaved
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
self.defaultProfile = configurationProfile
|
|
196
|
-
}
|
|
197
|
-
self.enableAirshipCallback = airshipEnable
|
|
198
|
-
|
|
199
|
-
if protectedregionslot >= 0{
|
|
200
|
-
self.protectedRegionSlot = protectedregionslot
|
|
201
|
-
}
|
|
202
|
-
else{
|
|
203
|
-
//Use last configured value
|
|
204
|
-
}
|
|
205
|
-
// Save it on preferences
|
|
206
|
-
|
|
207
|
-
defaults.set(self.woosmapKey, forKey: "WoosmapGeofenceService.woosmap")
|
|
208
|
-
defaults.set(self.defaultProfile, forKey: "WoosmapGeofenceService.profile")
|
|
209
|
-
defaults.set(airshipEnable, forKey: "WoosmapGeofenceService.AirshipCallbackEnable")
|
|
210
|
-
|
|
211
|
-
defaults.register(defaults: ["TrackingEnable": true,
|
|
212
|
-
"ModeHighfrequencyLocation": false,
|
|
213
|
-
"SearchAPIEnable": true,
|
|
214
|
-
"DistanceAPIEnable": true,
|
|
215
|
-
"searchAPICreationRegionEnable": true])
|
|
216
|
-
self.activateGeofenceService()
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/// Static instance of woosGeofencing service
|
|
220
|
-
/// - Parameters:
|
|
221
|
-
/// - woosmapKey: key use for woosmap service
|
|
222
|
-
/// - configurationProfile: configuration profile
|
|
223
|
-
@objc public static func setup(woosmapKey: String, configurationProfile: String,airshipTrackingEnable: Bool = false, protectedRegionSlot: Int = -1) {
|
|
224
|
-
let group = DispatchGroup()
|
|
225
|
-
group.enter()
|
|
226
|
-
DispatchQueue.main.async {
|
|
227
|
-
_shared = WoosmapGeofenceService.init( woosmapKey, configurationProfile,airshipTrackingEnable, protectedRegionSlot)
|
|
228
|
-
group.leave()
|
|
229
|
-
}
|
|
230
|
-
group.wait()
|
|
231
|
-
|
|
232
106
|
}
|
|
107
|
+
}
|
|
233
108
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
DispatchQueue.main.async {
|
|
239
|
-
_shared = WoosmapGeofenceService.init( "", "")
|
|
240
|
-
group.leave()
|
|
241
|
-
}
|
|
242
|
-
group.wait()
|
|
109
|
+
/// Status of HighfrequencyLocation Mode. On/Off
|
|
110
|
+
@objc public var modeHighfrequencyLocation: Bool {
|
|
111
|
+
get {
|
|
112
|
+
return self.sdkInstance?.getModeHighfrequencyLocation() ?? false
|
|
243
113
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
/// - Parameter key: woosmap key
|
|
247
|
-
/// - Throws: WoosGeofenceError incase of no key pass or empty
|
|
248
|
-
public func setWoosmapAPIKey(key: String) throws {
|
|
249
|
-
if key.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
|
|
250
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.invalidWoosmapKey)
|
|
251
|
-
} else {
|
|
252
|
-
self.woosmapKey = key
|
|
253
|
-
let group = DispatchGroup()
|
|
254
|
-
group.enter()
|
|
255
|
-
DispatchQueue.main.async {
|
|
256
|
-
WoosmapGeofenceManager.shared.setWoosmapAPIKey(key: self.woosmapKey)
|
|
257
|
-
group.leave()
|
|
258
|
-
}
|
|
259
|
-
group.wait()
|
|
260
|
-
let defaults = UserDefaults.standard
|
|
261
|
-
defaults.set(key, forKey: "WoosmapGeofenceService.woosmap")
|
|
262
|
-
}
|
|
114
|
+
set {
|
|
115
|
+
self.sdkInstance?.setModeHighfrequencyLocation(enable: newValue)
|
|
263
116
|
}
|
|
117
|
+
}
|
|
264
118
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if let savedProfile = ConfigurationProfile(rawValue: profile) {
|
|
270
|
-
let group = DispatchGroup()
|
|
271
|
-
group.enter()
|
|
272
|
-
DispatchQueue.main.async {
|
|
273
|
-
WoosmapGeofenceManager.shared.startTracking(configurationProfile: savedProfile)
|
|
274
|
-
group.leave()
|
|
275
|
-
}
|
|
276
|
-
group.wait()
|
|
277
|
-
self.defaultProfile = profile
|
|
278
|
-
let defaults = UserDefaults.standard
|
|
279
|
-
defaults.set(profile, forKey: "WoosmapGeofenceService.profile")
|
|
280
|
-
|
|
281
|
-
} else {
|
|
282
|
-
self.defaultProfile = ""
|
|
283
|
-
let defaults = UserDefaults.standard
|
|
284
|
-
defaults.set(self.defaultProfile, forKey: "WoosmapGeofenceService.profile")
|
|
285
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.invalidProfile)
|
|
286
|
-
}
|
|
287
|
-
// print ("Highfrequency \(WoosmapGeofenceManager.shared.getModeHighfrequencyLocation()) , TrackingState \(WoosmapGeofenceManager.shared.getTrackingState()) ")
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/// Stop tracking
|
|
291
|
-
public func stopTracking() {
|
|
292
|
-
WoosmapGeofenceManager.shared.stopTracking()
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/// activating WoosmapGeofencing with default parameters
|
|
296
|
-
private func activateGeofenceService() {
|
|
297
|
-
let status = CLLocationManager.authorizationStatus()
|
|
298
|
-
// Set private Woosmap key API
|
|
299
|
-
WoosmapGeofenceManager.shared.setWoosmapAPIKey(key: woosmapKey)
|
|
300
|
-
#if DEBUG
|
|
301
|
-
WoosmapGeofenceManager.shared.logLevel = .trace
|
|
302
|
-
#else
|
|
303
|
-
WoosmapGeofenceManager.shared.logLevel = .info
|
|
304
|
-
#endif
|
|
305
|
-
// Procteted slots
|
|
306
|
-
try? WoosmapGeofenceManager.shared.setProtectedRegionSlot(self.protectedRegionSlot)
|
|
307
|
-
// Set delegate of protocol Location, POI and Distance
|
|
308
|
-
WoosmapGeofenceManager.shared.getLocationService().locationServiceDelegate = dataLocation
|
|
309
|
-
WoosmapGeofenceManager.shared.getLocationService().searchAPIDataDelegate = dataPOI
|
|
310
|
-
WoosmapGeofenceManager.shared.getLocationService().distanceAPIDataDelegate = dataDistance
|
|
311
|
-
WoosmapGeofenceManager.shared.getLocationService().regionDelegate = dataRegion
|
|
312
|
-
|
|
313
|
-
// Enable Visit and set delegate of protocol Visit
|
|
314
|
-
WoosmapGeofenceManager.shared.getLocationService().visitDelegate = dataVisit
|
|
315
|
-
if(self.enableAirshipCallback){
|
|
316
|
-
// Set delagate for Airship Cloud
|
|
317
|
-
WoosmapGeofenceManager.shared.getLocationService().airshipEventsDelegate = airshipEvents
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Set delagate for Marketing Cloud
|
|
321
|
-
WoosmapGeofenceManager.shared.getLocationService().marketingCloudEventsDelegate = marketingCloudEvents
|
|
322
|
-
if defaultPOIRadius != "" {
|
|
323
|
-
WoosmapGeofenceManager.shared.setPoiRadius(radius: formatedRadius(radius: defaultPOIRadius))
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if status == .authorizedAlways || status == .authorizedWhenInUse {
|
|
327
|
-
if let savedProfile = ConfigurationProfile(rawValue: defaultProfile) {
|
|
328
|
-
if Thread.isMainThread {
|
|
329
|
-
WoosmapGeofenceManager.shared.startTracking(configurationProfile: savedProfile)
|
|
330
|
-
} else {
|
|
331
|
-
DispatchQueue.main.async {
|
|
332
|
-
WoosmapGeofenceManager.shared.startTracking(configurationProfile: savedProfile)
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
// Check if the authorization Status of location Manager
|
|
337
|
-
if CLLocationManager.authorizationStatus() != .notDetermined {
|
|
338
|
-
WoosmapGeofenceManager.shared.startMonitoringInBackground()
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
NotificationCenter.default.addObserver(self,
|
|
343
|
-
selector: #selector(appDidBecomeActive),
|
|
344
|
-
name: UIApplication.didBecomeActiveNotification,
|
|
345
|
-
object: nil)
|
|
346
|
-
|
|
347
|
-
NotificationCenter.default.addObserver(self, selector: #selector(appDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
|
|
348
|
-
|
|
349
|
-
NotificationCenter.default.addObserver(self, selector: #selector(appWillTerminate), name: UIApplication.willTerminateNotification, object: nil)
|
|
350
|
-
|
|
351
|
-
// MARK: Only for testing
|
|
352
|
-
// self.searchAPIRequestEnable = true
|
|
353
|
-
// self.distanceAPIRequestEnable = true
|
|
354
|
-
// self.searchAPICreationRegionEnable = true
|
|
355
|
-
// print ("\(WoosmapGeofenceManager.shared.getModeHighfrequencyLocation()) \(WoosmapGeofenceManager.shared.getTrackingState()) ")
|
|
119
|
+
/// Status of tracking state. On/Off
|
|
120
|
+
@objc public var trackingState: Bool {
|
|
121
|
+
get {
|
|
122
|
+
return self.sdkInstance?.getTrackingState() ?? false
|
|
356
123
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
/// - Parameters:
|
|
360
|
-
/// - identifier: Region id
|
|
361
|
-
/// - center: geoLocation point
|
|
362
|
-
/// - radius: radius of region
|
|
363
|
-
/// - type: String circle/isochrone
|
|
364
|
-
/// - Returns: Status for reagion created or not and new region id from system
|
|
365
|
-
public func addRegion(identifier: String, center: CLLocationCoordinate2D, radius: Int, type: String) -> (isCreate: Bool, identifier: String) {
|
|
366
|
-
return WoosmapGeofenceManager.shared.locationService.addRegion(identifier: identifier, center: center, radius: radius, type:type)
|
|
124
|
+
set {
|
|
125
|
+
self.sdkInstance?.setTrackingEnable(enable: newValue)
|
|
367
126
|
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// MARK: Application events
|
|
368
130
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
131
|
+
/// This callback received when application become active
|
|
132
|
+
@objc func appDidBecomeActive() {
|
|
133
|
+
let status = CLLocationManager().authorizationStatus
|
|
134
|
+
if status == .authorizedAlways || status == .authorizedWhenInUse {
|
|
135
|
+
DispatchQueue.main.async {
|
|
136
|
+
self.sdkInstance?.didBecomeActive()
|
|
137
|
+
}
|
|
373
138
|
}
|
|
139
|
+
}
|
|
374
140
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
141
|
+
/// This callback recived when application enter in background mode
|
|
142
|
+
@objc func appDidEnterBackground() {
|
|
143
|
+
if CLLocationManager().authorizationStatus != .notDetermined {
|
|
144
|
+
DispatchQueue.main.async {
|
|
145
|
+
self.sdkInstance?.startMonitoringInBackground()
|
|
146
|
+
self.sdkInstance?.getLocationService().stopUpdatingLocation()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// This callback received when application is terminated
|
|
152
|
+
@objc func appWillTerminate() {
|
|
153
|
+
self.sdkInstance?.setModeHighfrequencyLocation(enable: false)
|
|
154
|
+
}
|
|
155
|
+
// MARK: Init
|
|
156
|
+
|
|
157
|
+
/// Initialize woosGeofencing service with key saved in previous call
|
|
158
|
+
@MainActor
|
|
159
|
+
private override init() {
|
|
160
|
+
super.init()
|
|
161
|
+
let defaults = UserDefaults.standard
|
|
162
|
+
let woosmapKey =
|
|
163
|
+
defaults.string(forKey: "WoosmapGeofenceService.woosmap") ?? ""
|
|
164
|
+
let defaultProfile =
|
|
165
|
+
defaults.string(forKey: "WoosmapGeofenceService.profile") ?? ""
|
|
166
|
+
self.enableAirshipCallback = defaults.bool(
|
|
167
|
+
forKey: "WoosmapGeofenceService.AirshipCallbackEnable"
|
|
168
|
+
)
|
|
169
|
+
self.woosmapKey = woosmapKey
|
|
170
|
+
self.defaultProfile = defaultProfile
|
|
171
|
+
|
|
172
|
+
defaults.register(defaults: [
|
|
173
|
+
"TrackingEnable": true,
|
|
174
|
+
"ModeHighfrequencyLocation": false,
|
|
175
|
+
"SearchAPIEnable": true,
|
|
176
|
+
"DistanceAPIEnable": true,
|
|
177
|
+
"searchAPICreationRegionEnable": true,
|
|
178
|
+
"WoosmapGeofenceService.protectedregionslot": 0,
|
|
179
|
+
])
|
|
180
|
+
self.sdkInstance = WoosmapGeofenceManager.shared
|
|
181
|
+
self.activateGeofenceService()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// Initialize service with keys and profile
|
|
185
|
+
/// - Parameters:
|
|
186
|
+
/// - woosmapKey: key use for woosmap service
|
|
187
|
+
/// - configurationProfile: configuration profile
|
|
188
|
+
/// - airshipEnable: To enable airship callback
|
|
189
|
+
@MainActor
|
|
190
|
+
private init(
|
|
191
|
+
_ woosmapKey: String,
|
|
192
|
+
_ configurationProfile: String,
|
|
193
|
+
_ airshipEnable: Bool = false,
|
|
194
|
+
_ protectedregionslot: Int = -1
|
|
195
|
+
) {
|
|
196
|
+
super.init()
|
|
197
|
+
let defaults = UserDefaults.standard
|
|
198
|
+
if woosmapKey == "" {
|
|
199
|
+
let lastSaved =
|
|
200
|
+
defaults.string(forKey: "WoosmapGeofenceService.woosmap") ?? ""
|
|
201
|
+
self.woosmapKey = lastSaved
|
|
202
|
+
} else {
|
|
203
|
+
self.woosmapKey = woosmapKey
|
|
204
|
+
}
|
|
205
|
+
if configurationProfile == "" {
|
|
206
|
+
let lastSaved =
|
|
207
|
+
defaults.string(forKey: "WoosmapGeofenceService.profile") ?? ""
|
|
208
|
+
self.defaultProfile = lastSaved
|
|
209
|
+
} else {
|
|
210
|
+
self.defaultProfile = configurationProfile
|
|
211
|
+
}
|
|
212
|
+
self.enableAirshipCallback = airshipEnable
|
|
213
|
+
|
|
214
|
+
if protectedregionslot >= 0 {
|
|
215
|
+
self.protectedRegionSlot = protectedregionslot
|
|
216
|
+
} else {
|
|
217
|
+
//Use last configured value
|
|
218
|
+
}
|
|
219
|
+
// Save it on preferences
|
|
220
|
+
|
|
221
|
+
defaults.set(self.woosmapKey, forKey: "WoosmapGeofenceService.woosmap")
|
|
222
|
+
defaults.set(self.defaultProfile, forKey: "WoosmapGeofenceService.profile")
|
|
223
|
+
defaults.set(
|
|
224
|
+
airshipEnable,
|
|
225
|
+
forKey: "WoosmapGeofenceService.AirshipCallbackEnable"
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
defaults.register(defaults: [
|
|
229
|
+
"TrackingEnable": true,
|
|
230
|
+
"ModeHighfrequencyLocation": false,
|
|
231
|
+
"SearchAPIEnable": true,
|
|
232
|
+
"DistanceAPIEnable": true,
|
|
233
|
+
"searchAPICreationRegionEnable": true,
|
|
234
|
+
])
|
|
235
|
+
self.sdkInstance = WoosmapGeofenceManager.shared
|
|
236
|
+
self.activateGeofenceService()
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/// Static instance of woosGeofencing service
|
|
241
|
+
/// - Parameters:
|
|
242
|
+
/// - woosmapKey: key use for woosmap service
|
|
243
|
+
/// - configurationProfile: configuration profile
|
|
244
|
+
@objc public static func setup(
|
|
245
|
+
woosmapKey: String,
|
|
246
|
+
configurationProfile: String,
|
|
247
|
+
airshipTrackingEnable: Bool = false,
|
|
248
|
+
protectedRegionSlot: Int = -1
|
|
249
|
+
) {
|
|
250
|
+
DispatchQueue.main.sync {
|
|
251
|
+
_shared = WoosmapGeofenceService.init(
|
|
252
|
+
woosmapKey,
|
|
253
|
+
configurationProfile,
|
|
254
|
+
airshipTrackingEnable,
|
|
255
|
+
protectedRegionSlot
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// Creating instance for woosGeofencing service
|
|
261
|
+
@objc public static func setup() {
|
|
262
|
+
DispatchQueue.main.sync {
|
|
263
|
+
_shared = WoosmapGeofenceService.init("", "")
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/// Setting up woosmap key
|
|
268
|
+
/// - Parameter key: woosmap key
|
|
269
|
+
/// - Throws: WoosGeofenceError incase of no key pass or empty
|
|
270
|
+
/// @MainActor
|
|
271
|
+
public func setWoosmapAPIKey(key: String) throws {
|
|
272
|
+
if key.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
|
|
273
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.invalidWoosmapKey)
|
|
274
|
+
} else {
|
|
275
|
+
self.woosmapKey = key
|
|
276
|
+
self.sdkInstance?.setWoosmapAPIKey(key: self.woosmapKey)
|
|
277
|
+
let defaults = UserDefaults.standard
|
|
278
|
+
defaults.set(key, forKey: "WoosmapGeofenceService.woosmap")
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/// Change tracking mode with new profile
|
|
283
|
+
/// - Parameter profile: profile for tracking. liveTracking / passiveTracking / visitsTracking
|
|
284
|
+
/// - Throws: in case of wrong profile provided it return error invalidProfile
|
|
285
|
+
public func startTracking(profile: String) throws {
|
|
286
|
+
if let savedProfile = ConfigurationProfile(rawValue: profile) {
|
|
287
|
+
DispatchQueue.main.sync {
|
|
288
|
+
self.sdkInstance?.startTracking(configurationProfile: savedProfile)
|
|
289
|
+
}
|
|
290
|
+
self.defaultProfile = profile
|
|
291
|
+
let defaults = UserDefaults.standard
|
|
292
|
+
defaults.set(profile, forKey: "WoosmapGeofenceService.profile")
|
|
293
|
+
|
|
294
|
+
} else {
|
|
295
|
+
self.defaultProfile = ""
|
|
296
|
+
let defaults = UserDefaults.standard
|
|
297
|
+
defaults.set(
|
|
298
|
+
self.defaultProfile,
|
|
299
|
+
forKey: "WoosmapGeofenceService.profile"
|
|
300
|
+
)
|
|
301
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.invalidProfile)
|
|
302
|
+
}
|
|
303
|
+
// print ("Highfrequency \(self.sdkInstance?.getModeHighfrequencyLocation()) , TrackingState \(self.sdkInstance?.getTrackingState()) ")
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/// Stop tracking
|
|
307
|
+
public func stopTracking() {
|
|
308
|
+
self.sdkInstance?.stopTracking()
|
|
309
|
+
_isServiceRunning = false
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/// activating WoosmapGeofencing with default parameters
|
|
313
|
+
private func activateGeofenceService() {
|
|
314
|
+
let status = CLLocationManager().authorizationStatus
|
|
315
|
+
// Set private Woosmap key API
|
|
316
|
+
sdkInstance?.setWoosmapAPIKey(key: woosmapKey)
|
|
317
|
+
#if DEBUG
|
|
318
|
+
self.sdkInstance?.logLevel = .trace
|
|
319
|
+
#else
|
|
320
|
+
self.sdkInstance?.logLevel = .info
|
|
321
|
+
#endif
|
|
322
|
+
// Procteted slots
|
|
323
|
+
try? self.sdkInstance?.setProtectedRegionSlot(self.protectedRegionSlot)
|
|
324
|
+
// Set delegate of protocol Location, POI and Distance
|
|
325
|
+
self.sdkInstance?.getLocationService().locationServiceDelegate =
|
|
326
|
+
dataLocation
|
|
327
|
+
self.sdkInstance?.getLocationService().searchAPIDataDelegate = dataPOI
|
|
328
|
+
self.sdkInstance?.getLocationService().distanceAPIDataDelegate =
|
|
329
|
+
dataDistance
|
|
330
|
+
self.sdkInstance?.getLocationService().regionDelegate = dataRegion
|
|
331
|
+
|
|
332
|
+
// Enable Visit and set delegate of protocol Visit
|
|
333
|
+
self.sdkInstance?.getLocationService().visitDelegate = dataVisit
|
|
334
|
+
if self.enableAirshipCallback {
|
|
335
|
+
// Set delagate for Airship Cloud
|
|
336
|
+
self.sdkInstance?.getLocationService().airshipEventsDelegate =
|
|
337
|
+
airshipEvents
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Set delagate for Marketing Cloud
|
|
341
|
+
self.sdkInstance?.getLocationService().marketingCloudEventsDelegate =
|
|
342
|
+
marketingCloudEvents
|
|
343
|
+
if defaultPOIRadius != "" {
|
|
344
|
+
self.sdkInstance?.setPoiRadius(
|
|
345
|
+
radius: formatedRadius(radius: defaultPOIRadius)
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if status == .authorizedAlways || status == .authorizedWhenInUse {
|
|
350
|
+
if let savedProfile = ConfigurationProfile(rawValue: defaultProfile) {
|
|
351
|
+
self.sdkInstance?.startTracking(configurationProfile: savedProfile)
|
|
352
|
+
_isServiceRunning = true
|
|
353
|
+
} else if defaultProfile != "" {
|
|
354
|
+
let profilelocation = defaultProfile.split(separator: ":")
|
|
355
|
+
if profilelocation.count == 2 {
|
|
356
|
+
let pURL = getCustomProfileURL(
|
|
357
|
+
mode: String(profilelocation[0]),
|
|
358
|
+
source: String(profilelocation[1])
|
|
359
|
+
)
|
|
360
|
+
if pURL != "" {
|
|
361
|
+
let (status, _) = self.sdkInstance!.startCustomTracking(url: pURL)
|
|
362
|
+
if status {
|
|
363
|
+
_isServiceRunning = true
|
|
384
364
|
}
|
|
365
|
+
}
|
|
385
366
|
}
|
|
367
|
+
}
|
|
368
|
+
// Check if the authorization Status of location Manager
|
|
369
|
+
if CLLocationManager().authorizationStatus != .notDetermined {
|
|
370
|
+
self.sdkInstance?.startMonitoringInBackground()
|
|
371
|
+
}
|
|
386
372
|
}
|
|
387
373
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
///
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
374
|
+
NotificationCenter.default.addObserver(
|
|
375
|
+
self,
|
|
376
|
+
selector: #selector(appDidBecomeActive),
|
|
377
|
+
name: UIApplication.didBecomeActiveNotification,
|
|
378
|
+
object: nil
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
NotificationCenter.default.addObserver(
|
|
382
|
+
self,
|
|
383
|
+
selector: #selector(appDidEnterBackground),
|
|
384
|
+
name: UIApplication.didEnterBackgroundNotification,
|
|
385
|
+
object: nil
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
NotificationCenter.default.addObserver(
|
|
389
|
+
self,
|
|
390
|
+
selector: #selector(appWillTerminate),
|
|
391
|
+
name: UIApplication.willTerminateNotification,
|
|
392
|
+
object: nil
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
// MARK: Only for testing
|
|
396
|
+
// self.searchAPIRequestEnable = true
|
|
397
|
+
// self.distanceAPIRequestEnable = true
|
|
398
|
+
// self.searchAPICreationRegionEnable = true
|
|
399
|
+
// print ("\(self.sdkInstance?.getModeHighfrequencyLocation()) \(self.sdkInstance?.getTrackingState()) ")
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/// Adding new region
|
|
403
|
+
/// - Parameters:
|
|
404
|
+
/// - identifier: Region id
|
|
405
|
+
/// - center: geoLocation point
|
|
406
|
+
/// - radius: radius of region
|
|
407
|
+
/// - type: String circle/isochrone
|
|
408
|
+
/// - Returns: Status for reagion created or not and new region id from system
|
|
409
|
+
public func addRegion(
|
|
410
|
+
identifier: String,
|
|
411
|
+
center: CLLocationCoordinate2D,
|
|
412
|
+
radius: Int,
|
|
413
|
+
type: String
|
|
414
|
+
) -> (isCreate: Bool, identifier: String) {
|
|
415
|
+
return self.sdkInstance?.locationService.addRegion(
|
|
416
|
+
identifier: identifier,
|
|
417
|
+
center: center,
|
|
418
|
+
radius: radius,
|
|
419
|
+
type: type
|
|
420
|
+
) ?? (false, "")
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/// Remove region from system
|
|
424
|
+
/// - Parameter center: geoLocation point of region
|
|
425
|
+
public func removeRegion(center: CLLocationCoordinate2D) {
|
|
426
|
+
self.sdkInstance?.locationService.removeRegion(center: center)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/// Remove region from system
|
|
430
|
+
/// - Parameter identifier: region id assined for region
|
|
431
|
+
public func removeRegion(identifier: String) {
|
|
432
|
+
if let regionInfo = getRegions(id: identifier) {
|
|
433
|
+
if regionInfo.type == "circle" {
|
|
434
|
+
self.sdkInstance?.locationService.removeRegion(
|
|
435
|
+
identifier: regionInfo.identifier
|
|
436
|
+
)
|
|
437
|
+
} else {
|
|
438
|
+
RegionIsochrones.removeRegionIsochrone(id: regionInfo.identifier)
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/// Get location information for geopoint from woos system
|
|
444
|
+
/// - Parameters:
|
|
445
|
+
/// - location: geopoint for location
|
|
446
|
+
/// - locationId: id recorded for that location
|
|
447
|
+
public func searchAPIRequest(
|
|
448
|
+
location: CLLocationCoordinate2D,
|
|
449
|
+
locationId: String = ""
|
|
450
|
+
) {
|
|
451
|
+
// TODO: Missing implementation
|
|
452
|
+
//self.sdkInstance?.getLocationService().searchAPIRequest(location: CLLocation.init(latitude: location.latitude, longitude: location.longitude), locationId: locationId)
|
|
453
|
+
}
|
|
454
|
+
// TODO: Missing implementation
|
|
455
|
+
// /// Get distnce between location point and origin
|
|
456
|
+
// /// - Parameters:
|
|
457
|
+
// /// - locationOrigin: origin geolocation
|
|
458
|
+
// /// - coordinatesDest: destination geolocation
|
|
459
|
+
// /// - locationId: id recorded for that location
|
|
460
|
+
// public func distanceAPIRequest(locationOrigin: CLLocationCoordinate2D, coordinatesDest: CLLocation, locationId: String = "") {
|
|
461
|
+
// let latDest = coordinatesDest.coordinate.latitude
|
|
462
|
+
// let lngDest = coordinatesDest.coordinate.longitude
|
|
463
|
+
// let originLocation = CLLocation.init(latitude: locationOrigin.latitude,
|
|
464
|
+
// longitude: locationOrigin.longitude)
|
|
465
|
+
// self.sdkInstance?.getLocationService().distanceAPIRequest(locationOrigin: originLocation,
|
|
466
|
+
// coordinatesDest: [(latDest, lngDest)],
|
|
467
|
+
// locationId: locationId)
|
|
468
|
+
// }
|
|
469
|
+
//
|
|
470
|
+
// /// Get distnce between location point and origin
|
|
471
|
+
// /// - Parameters:
|
|
472
|
+
// /// - locationOrigin: origin geolocation
|
|
473
|
+
// /// - locationId: id recorded for that location
|
|
474
|
+
// public func distanceAPIRequest(locationOrigin: CLLocationCoordinate2D, locationId: String = "") {
|
|
475
|
+
// if let poi = DataPOI().getPOIbyLocationID(locationId: locationId) {
|
|
476
|
+
// let latDest = poi.latitude
|
|
477
|
+
// let lngDest = poi.longitude
|
|
478
|
+
// let originLocation = CLLocation.init(latitude: locationOrigin.latitude,
|
|
479
|
+
// longitude: locationOrigin.longitude)
|
|
480
|
+
// self.sdkInstance?.getLocationService().distanceAPIRequest(locationOrigin: originLocation,
|
|
481
|
+
// coordinatesDest: [(latDest, lngDest)],
|
|
482
|
+
// locationId: locationId)
|
|
483
|
+
// }
|
|
484
|
+
//
|
|
485
|
+
// }
|
|
486
|
+
|
|
487
|
+
/// List all locations capture by system
|
|
488
|
+
/// - Returns: Array of location captured
|
|
489
|
+
public func getLocations() -> [Location] {
|
|
490
|
+
let locations = DataLocation().readLocations()
|
|
491
|
+
return locations
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
public func getLocations(id: String) -> Location? {
|
|
495
|
+
let locations = DataLocation().readLocations(id: id)
|
|
496
|
+
return locations
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/// List all POIs capture by system
|
|
500
|
+
/// - Returns: Array of POIs
|
|
501
|
+
public func getPOIs() -> [POI] {
|
|
502
|
+
let poi = DataPOI().readPOI()
|
|
503
|
+
return poi
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/// List all POIs capture by system
|
|
507
|
+
/// - Returns: Array of POIs
|
|
508
|
+
public func getPOIs(id: String) -> POI? {
|
|
509
|
+
let poi = DataPOI().readPOI(id: id)
|
|
510
|
+
return poi
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
///Fetch beacon info from storage
|
|
514
|
+
/// - Returns: Array of Beacon POIs
|
|
515
|
+
public func getIndoorBeacons(id: String?) -> [IndoorBeacon]? {
|
|
516
|
+
let info = DataPOI().readIndoorBeaconPOI(venueid: id)
|
|
517
|
+
return info
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
///Delete Becaon info from storage
|
|
521
|
+
public func deleteIndoorBeacons() {
|
|
522
|
+
IndoorBeacons.deleteAll()
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/// List all intrest zone capture by system
|
|
526
|
+
/// - Returns: Array of zones
|
|
527
|
+
public func getZOIs() -> [ZOI] {
|
|
528
|
+
let zoi = DataZOI().readZOIs()
|
|
529
|
+
return zoi
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/// List all region capture by system
|
|
533
|
+
/// - Returns: Array of regions
|
|
534
|
+
public func getRegions() -> [Region] {
|
|
535
|
+
var regions = DataRegion().readRegions()
|
|
536
|
+
let IsochroneRegion = DataRegion().readIsochroneRegions()
|
|
537
|
+
IsochroneRegion.forEach { item in
|
|
538
|
+
let customRegion = Region(
|
|
539
|
+
latitude: item.latitude,
|
|
540
|
+
longitude: item.latitude,
|
|
541
|
+
radius: Double(item.radius),
|
|
542
|
+
dateCaptured: Date(),
|
|
543
|
+
identifier: item.identifier ?? "-",
|
|
544
|
+
didEnter: false,
|
|
545
|
+
fromPositionDetection: false,
|
|
546
|
+
eventName: ""
|
|
547
|
+
)
|
|
548
|
+
customRegion.type = item.type
|
|
549
|
+
regions.append(customRegion)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if let locationService = self.sdkInstance?.locationService {
|
|
553
|
+
if let customRegion = locationService.locationManager?.monitoredRegions {
|
|
554
|
+
customRegion.forEach { item in
|
|
555
|
+
if locationService.getRegionType(identifier: item.normalizeIdentifier)
|
|
556
|
+
== RegionType.custom
|
|
557
|
+
{
|
|
558
|
+
|
|
559
|
+
let customRegionItem = Region(
|
|
560
|
+
latitude: 0,
|
|
561
|
+
longitude: 0,
|
|
562
|
+
radius: 0,
|
|
563
|
+
dateCaptured: Date(),
|
|
564
|
+
identifier: item.normalizeIdentifier,
|
|
565
|
+
didEnter: false,
|
|
566
|
+
fromPositionDetection: false,
|
|
567
|
+
eventName: ""
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
customRegionItem.identifier = item.normalizeIdentifier
|
|
571
|
+
if let circleRegion = item as? CLCircularRegion {
|
|
572
|
+
customRegionItem.latitude = circleRegion.center.latitude
|
|
573
|
+
customRegionItem.longitude = circleRegion.center.longitude
|
|
574
|
+
customRegionItem.radius = circleRegion.radius
|
|
575
|
+
customRegionItem.type = "circle"
|
|
503
576
|
}
|
|
577
|
+
regions.append(customRegionItem)
|
|
578
|
+
}
|
|
504
579
|
}
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return regions
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/// Return region info
|
|
586
|
+
/// - Parameter id: region id
|
|
587
|
+
/// - Returns: Region
|
|
588
|
+
public func getRegions(id: String) -> Region? {
|
|
589
|
+
var regionId = id
|
|
590
|
+
if let locationService = self.sdkInstance?.locationService {
|
|
591
|
+
var regionType = locationService.getRegionType(identifier: id)
|
|
592
|
+
if regionType == .none {
|
|
593
|
+
regionId = "custom<id>\(regionId)"
|
|
594
|
+
}
|
|
595
|
+
regionType = locationService.getRegionType(identifier: regionId)
|
|
596
|
+
if regionType == RegionType.custom { //Custom region
|
|
597
|
+
if let customRegions = locationService.locationManager?.monitoredRegions
|
|
598
|
+
{
|
|
599
|
+
if let watchRegion = customRegions.first(where: { item in
|
|
600
|
+
return item.normalizeIdentifier == regionId
|
|
601
|
+
}) {
|
|
602
|
+
let customRegion = Region(
|
|
603
|
+
latitude: 0,
|
|
604
|
+
longitude: 0,
|
|
605
|
+
radius: 0,
|
|
606
|
+
dateCaptured: Date(),
|
|
607
|
+
identifier: "-",
|
|
608
|
+
didEnter: false,
|
|
609
|
+
fromPositionDetection: false,
|
|
610
|
+
eventName: ""
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
customRegion.identifier = watchRegion.normalizeIdentifier
|
|
614
|
+
if let circleRegion = watchRegion as? CLCircularRegion {
|
|
615
|
+
customRegion.latitude = circleRegion.center.latitude
|
|
616
|
+
customRegion.longitude = circleRegion.center.longitude
|
|
617
|
+
customRegion.radius = circleRegion.radius
|
|
618
|
+
customRegion.type = "circle"
|
|
537
619
|
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if let regions = DataRegion().readRegions(id: id){ //POI
|
|
541
|
-
return regions
|
|
542
|
-
}
|
|
543
|
-
if let regions = DataRegion().readIsochroneRegions(id: id){ //Isochrone Zone
|
|
544
|
-
|
|
545
|
-
let customRegion = Region(latitude: 0, longitude: 0, radius: 0, dateCaptured: Date(), identifier: "-", didEnter: false, fromPositionDetection: false, eventName: "")
|
|
546
|
-
customRegion.identifier = regions.identifier ?? "-"
|
|
547
|
-
customRegion.latitude = regions.latitude
|
|
548
|
-
customRegion.longitude = regions.longitude
|
|
549
|
-
customRegion.radius = Double(regions.radius)
|
|
550
|
-
customRegion.type = regions.type
|
|
551
620
|
return customRegion
|
|
621
|
+
}
|
|
552
622
|
}
|
|
553
|
-
|
|
554
|
-
return nil
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
/// List all visits capture by system
|
|
558
|
-
/// - Returns: Array of visits
|
|
559
|
-
public func getVisits() -> [Visit] {
|
|
560
|
-
let visit = DataVisit().readVisits()
|
|
561
|
-
return visit
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/// Delete all visits from system
|
|
565
|
-
public func deleteVisits() {
|
|
566
|
-
DataVisit().eraseVisits()
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/// Delete all zois form system
|
|
570
|
-
public func deleteZoi() {
|
|
571
|
-
DataZOI().eraseZOIs()
|
|
572
|
-
}
|
|
573
|
-
/// Delete all POI from system
|
|
574
|
-
public func deletePOI() {
|
|
575
|
-
DataPOI().erasePOI()
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/// Delete all location from system
|
|
579
|
-
public func deleteAllLocations() {
|
|
580
|
-
DataLocation().eraseLocations()
|
|
581
|
-
// Native SDK Works independently
|
|
582
|
-
// DataPOI().erasePOI()
|
|
623
|
+
}
|
|
583
624
|
}
|
|
584
625
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
626
|
+
if let regions = DataRegion().readRegions(id: id) { //POI
|
|
627
|
+
return regions
|
|
628
|
+
}
|
|
629
|
+
if let regions = DataRegion().readIsochroneRegions(id: id) { //Isochrone Zone
|
|
630
|
+
|
|
631
|
+
let customRegion = Region(
|
|
632
|
+
latitude: 0,
|
|
633
|
+
longitude: 0,
|
|
634
|
+
radius: 0,
|
|
635
|
+
dateCaptured: Date(),
|
|
636
|
+
identifier: "-",
|
|
637
|
+
didEnter: false,
|
|
638
|
+
fromPositionDetection: false,
|
|
639
|
+
eventName: ""
|
|
640
|
+
)
|
|
641
|
+
customRegion.identifier = regions.identifier ?? "-"
|
|
642
|
+
customRegion.latitude = regions.latitude
|
|
643
|
+
customRegion.longitude = regions.longitude
|
|
644
|
+
customRegion.radius = Double(regions.radius)
|
|
645
|
+
customRegion.type = regions.type
|
|
646
|
+
return customRegion
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return nil
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/// List all visits capture by system
|
|
653
|
+
/// - Returns: Array of visits
|
|
654
|
+
public func getVisits() -> [Visit] {
|
|
655
|
+
let visit = DataVisit().readVisits()
|
|
656
|
+
return visit
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/// Delete all visits from system
|
|
660
|
+
public func deleteVisits() {
|
|
661
|
+
DataVisit().eraseVisits()
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/// Delete all zois form system
|
|
665
|
+
public func deleteZoi() {
|
|
666
|
+
DataZOI().eraseZOIs()
|
|
667
|
+
}
|
|
668
|
+
/// Delete all POI from system
|
|
669
|
+
public func deletePOI() {
|
|
670
|
+
DataPOI().erasePOI()
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/// Delete all location from system
|
|
674
|
+
public func deleteAllLocations() {
|
|
675
|
+
DataLocation().eraseLocations()
|
|
676
|
+
// Native SDK Works independently
|
|
677
|
+
// DataPOI().erasePOI()
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/// Delete all ZOI regions
|
|
681
|
+
public func deleteAllZoiRegion() {
|
|
682
|
+
self.sdkInstance?.locationService.removeRegions(type: RegionType.custom)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/// Delete all POI regions
|
|
686
|
+
public func deleteAllPoiRegion() {
|
|
687
|
+
self.sdkInstance?.locationService.removeRegions(type: RegionType.poi)
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/// Delete regions by id
|
|
691
|
+
/// - Parameter id: region id
|
|
692
|
+
/// - Returns: deleted
|
|
693
|
+
public func deleteRegions(id: String) throws {
|
|
694
|
+
if let regionInfo = getRegions(id: id) {
|
|
695
|
+
if regionInfo.type == "circle" {
|
|
696
|
+
self.sdkInstance?.locationService.removeRegion(
|
|
697
|
+
identifier: regionInfo.identifier
|
|
698
|
+
)
|
|
699
|
+
} else {
|
|
700
|
+
DataRegion().eraseRegions(id: regionInfo.identifier)
|
|
701
|
+
}
|
|
702
|
+
} else {
|
|
703
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.regionid_notexist)
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/// Delete all regions
|
|
709
|
+
public func deleteAllRegion() {
|
|
710
|
+
DataRegion().eraseRegions()
|
|
711
|
+
self.sdkInstance?.locationService.removeRegions(type: RegionType.none)
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
@objc static public func mockdata() {
|
|
715
|
+
if WoosmapGeofenceService.shared == nil {
|
|
716
|
+
WoosmapGeofenceService.setup()
|
|
717
|
+
}
|
|
718
|
+
MockDataVisit().mockVisitData()
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/// Setting up SFMCCredentials
|
|
722
|
+
/// - Parameter credentials: Key/value pair for credentials settings
|
|
723
|
+
/// - Throws: Error for required keys
|
|
724
|
+
@objc public func setSFMCCredentials(credentials: [String: String]) throws {
|
|
725
|
+
var requiredSatisfied = true
|
|
726
|
+
if credentials["authenticationBaseURI"] == nil {
|
|
727
|
+
requiredSatisfied = false
|
|
728
|
+
throw WoosGeofenceError(
|
|
729
|
+
WoosmapGeofenceMessage.required_authenticationBaseURI
|
|
730
|
+
)
|
|
731
|
+
} else if credentials["restBaseURI"] == nil {
|
|
732
|
+
requiredSatisfied = false
|
|
733
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.required_restBaseURI)
|
|
734
|
+
} else if credentials["client_id"] == nil {
|
|
735
|
+
requiredSatisfied = false
|
|
736
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.required_client_id)
|
|
737
|
+
} else if credentials["client_secret"] == nil {
|
|
738
|
+
requiredSatisfied = false
|
|
739
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.required_client_secret)
|
|
740
|
+
} else if credentials["contactKey"] == nil {
|
|
741
|
+
requiredSatisfied = false
|
|
742
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.required_contactKey)
|
|
743
|
+
}
|
|
744
|
+
if requiredSatisfied {
|
|
745
|
+
self.sdkInstance?.setSFMCCredentials(credentials: credentials)
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/// Setting POI redious
|
|
750
|
+
/// - Parameter radius: integer or string for radius value
|
|
751
|
+
public func setPoiRadius(radius: String) {
|
|
752
|
+
self.defaultPOIRadius = radius
|
|
753
|
+
self.sdkInstance?.setPoiRadius(radius: formatedRadius(radius: radius))
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/// Format String value to proper datatype
|
|
757
|
+
/// - Parameter radius: radius of POI
|
|
758
|
+
/// - Returns: Formatted radius
|
|
759
|
+
private func formatedRadius(radius: String) -> Any {
|
|
760
|
+
if let poiRadius = Int(radius) {
|
|
761
|
+
return poiRadius
|
|
762
|
+
} else if let poiRadius = Double(radius) {
|
|
763
|
+
return poiRadius
|
|
764
|
+
} else {
|
|
765
|
+
return radius
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
private func isRegionIDExist(id: String) -> Bool {
|
|
769
|
+
if getRegions(id: id) != nil {
|
|
770
|
+
return true
|
|
771
|
+
}
|
|
772
|
+
return false
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/// Convert Absolute URL for custom profile
|
|
776
|
+
/// - Parameters:
|
|
777
|
+
/// - mode: location of profle local or external
|
|
778
|
+
/// - source: file name
|
|
779
|
+
/// - Returns: Absolute URL
|
|
780
|
+
private func getCustomProfileURL(mode: String, source: String) -> String {
|
|
781
|
+
var customProfile: String = ""
|
|
782
|
+
if mode == "local" {
|
|
783
|
+
let bundle = Bundle.main //Bundle(for: Self.self)
|
|
784
|
+
if let url = bundle.url(forResource: source, withExtension: nil) {
|
|
785
|
+
customProfile = url.absoluteString
|
|
786
|
+
}
|
|
787
|
+
} else if mode == "external" {
|
|
788
|
+
customProfile = source
|
|
789
|
+
}
|
|
790
|
+
return customProfile
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
public func startCustomTracking(
|
|
794
|
+
mode: String,
|
|
795
|
+
source: String,
|
|
796
|
+
completion: @escaping (_ Value: Bool, _ Error: WoosGeofenceError?) -> Void
|
|
797
|
+
) {
|
|
798
|
+
let customProfile: String = getCustomProfileURL(mode: mode, source: source)
|
|
799
|
+
if mode == "local" {
|
|
800
|
+
if customProfile == "" {
|
|
801
|
+
completion(
|
|
802
|
+
false,
|
|
803
|
+
WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilefile)
|
|
804
|
+
)
|
|
805
|
+
}
|
|
806
|
+
} else if mode == "external" {
|
|
807
|
+
if customProfile == "" {
|
|
808
|
+
completion(
|
|
809
|
+
false,
|
|
810
|
+
WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilesourcetype)
|
|
811
|
+
)
|
|
812
|
+
}
|
|
588
813
|
}
|
|
589
814
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
815
|
+
if customProfile != "" {
|
|
816
|
+
DispatchQueue.main.async {
|
|
817
|
+
let (status, errors) = self.sdkInstance!.startCustomTracking(
|
|
818
|
+
url: customProfile
|
|
819
|
+
)
|
|
594
820
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
else{
|
|
608
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.regionid_notexist )
|
|
821
|
+
if status == false {
|
|
822
|
+
completion(false, WoosGeofenceError(errors[0]))
|
|
823
|
+
} else {
|
|
824
|
+
completion(true, nil)
|
|
825
|
+
self.defaultProfile = "\(mode):\(source)"
|
|
826
|
+
let defaults = UserDefaults.standard
|
|
827
|
+
defaults.set(
|
|
828
|
+
self.defaultProfile,
|
|
829
|
+
forKey: "WoosmapGeofenceService.profile"
|
|
830
|
+
)
|
|
609
831
|
}
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
/// Delete all regions
|
|
614
|
-
public func deleteAllRegion() {
|
|
615
|
-
DataRegion().eraseRegions()
|
|
616
|
-
WoosmapGeofenceManager.shared.locationService.removeRegions(type: RegionType.none)
|
|
832
|
+
}
|
|
617
833
|
}
|
|
618
834
|
|
|
619
|
-
|
|
620
|
-
if WoosmapGeofenceService.shared == nil {
|
|
621
|
-
WoosmapGeofenceService.setup()
|
|
622
|
-
}
|
|
623
|
-
MockDataVisit().mockVisitData()
|
|
624
|
-
}
|
|
835
|
+
}
|
|
625
836
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
else if credentials["restBaseURI"] == nil {
|
|
636
|
-
requiredSatisfied = false
|
|
637
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.required_restBaseURI)
|
|
638
|
-
}
|
|
639
|
-
else if credentials["client_id"] == nil {
|
|
640
|
-
requiredSatisfied = false
|
|
641
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.required_client_id)
|
|
642
|
-
}
|
|
643
|
-
else if credentials["client_secret"] == nil {
|
|
644
|
-
requiredSatisfied = false
|
|
645
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.required_client_secret)
|
|
646
|
-
}
|
|
647
|
-
else if credentials["contactKey"] == nil {
|
|
648
|
-
requiredSatisfied = false
|
|
649
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.required_contactKey)
|
|
650
|
-
}
|
|
651
|
-
if requiredSatisfied {
|
|
652
|
-
WoosmapGeofenceManager.shared.setSFMCCredentials(credentials: credentials)
|
|
837
|
+
public func startCustomTracking1(mode: String, source: String) throws {
|
|
838
|
+
if mode == "local" {
|
|
839
|
+
let bundle = Bundle.main //Bundle(for: Self.self)
|
|
840
|
+
if let url = bundle.url(forResource: source, withExtension: nil) {
|
|
841
|
+
let (status, errors) = self.sdkInstance!.startCustomTracking(
|
|
842
|
+
url: url.absoluteString
|
|
843
|
+
)
|
|
844
|
+
if status == false {
|
|
845
|
+
throw WoosGeofenceError(errors[0])
|
|
653
846
|
}
|
|
847
|
+
} else {
|
|
848
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilefile)
|
|
849
|
+
}
|
|
850
|
+
} else if mode == "external" {
|
|
851
|
+
let (status, errors) = self.sdkInstance!.startCustomTracking(url: source)
|
|
852
|
+
if status == false {
|
|
853
|
+
throw WoosGeofenceError(errors[0])
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
throw WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilesourcetype)
|
|
654
857
|
}
|
|
655
858
|
|
|
656
|
-
|
|
657
|
-
/// - Parameter radius: integer or string for radius value
|
|
658
|
-
public func setPoiRadius(radius: String) {
|
|
659
|
-
self.defaultPOIRadius = radius
|
|
660
|
-
WoosmapGeofenceManager.shared.setPoiRadius(radius: formatedRadius(radius: radius))
|
|
661
|
-
}
|
|
859
|
+
}
|
|
662
860
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if let poiRadius = Int(radius){
|
|
668
|
-
return poiRadius
|
|
669
|
-
}
|
|
670
|
-
else if let poiRadius = Double(radius){
|
|
671
|
-
return poiRadius
|
|
672
|
-
}
|
|
673
|
-
else{
|
|
674
|
-
return radius
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
private func isRegionIDExist(id: String) -> Bool{
|
|
678
|
-
if let _ = getRegions(id: id){
|
|
679
|
-
return true
|
|
680
|
-
}
|
|
681
|
-
return false
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
public func startCustomTracking(mode: String, source:String, completion: @escaping (_ Value: Bool, _ Error: WoosGeofenceError?)->()){
|
|
685
|
-
let group = DispatchGroup()
|
|
686
|
-
group.enter()
|
|
687
|
-
DispatchQueue.main.async {
|
|
688
|
-
if(mode == "local"){
|
|
689
|
-
let bundle = Bundle.main //Bundle(for: Self.self)
|
|
690
|
-
if let url = bundle.url(forResource: source, withExtension: nil){
|
|
691
|
-
let (status,errors) = WoosmapGeofenceManager.shared.startCustomTracking(url: url.absoluteString)
|
|
692
|
-
|
|
693
|
-
if(status == false){
|
|
694
|
-
completion(false,WoosGeofenceError(errors[0]))
|
|
695
|
-
}
|
|
696
|
-
else{
|
|
697
|
-
completion(true,nil)
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
else{
|
|
701
|
-
completion(false,WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilefile))
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
else if(mode == "external"){
|
|
705
|
-
let (status,errors) = WoosmapGeofenceManager.shared.startCustomTracking(url: source)
|
|
706
|
-
if(status == false){
|
|
707
|
-
completion(false,WoosGeofenceError(errors[0]))
|
|
708
|
-
}
|
|
709
|
-
else{
|
|
710
|
-
completion(true,nil)
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
else{
|
|
714
|
-
completion(false,WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilesourcetype))
|
|
715
|
-
}
|
|
716
|
-
group.leave()
|
|
717
|
-
}
|
|
718
|
-
group.wait()
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
public func startCustomTracking1(mode: String, source:String) throws{
|
|
722
|
-
if(mode == "local"){
|
|
723
|
-
let bundle = Bundle.main //Bundle(for: Self.self)
|
|
724
|
-
if let url = bundle.url(forResource: source, withExtension: nil){
|
|
725
|
-
let (status,errors) = WoosmapGeofenceManager.shared.startCustomTracking(url: url.absoluteString)
|
|
726
|
-
if(status == false){
|
|
727
|
-
throw WoosGeofenceError(errors[0])
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
else{
|
|
731
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilefile)
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
else if(mode == "external"){
|
|
735
|
-
let (status,errors) = WoosmapGeofenceManager.shared.startCustomTracking(url: source)
|
|
736
|
-
if(status == false){
|
|
737
|
-
throw WoosGeofenceError(errors[0])
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
else{
|
|
741
|
-
throw WoosGeofenceError(WoosmapGeofenceMessage.invalid_profilesourcetype )
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
}
|
|
861
|
+
///Refresh POI info in storage
|
|
862
|
+
public func refreshPOI() {
|
|
863
|
+
self.sdkInstance?.refreshPOIs()
|
|
864
|
+
}
|
|
745
865
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
public func isSearviceActive()-> Bool {
|
|
752
|
-
if(WoosmapGeofenceManager.shared.locationService.locationManager == nil){
|
|
753
|
-
return false
|
|
754
|
-
}
|
|
755
|
-
return true
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
/// Setting Region Slots to reserver for other 3rd Party SDK to use it
|
|
759
|
-
/// - Parameter slots: Maximum 3 slots allow
|
|
760
|
-
public func setProtectedRegionSlot(slots: Int) throws{
|
|
761
|
-
try WoosmapGeofenceManager.shared.setProtectedRegionSlot(slots)
|
|
762
|
-
self.protectedRegionSlot = slots
|
|
866
|
+
public func isSearviceActive() -> Bool {
|
|
867
|
+
if self.sdkInstance?.locationService.locationManager == nil {
|
|
868
|
+
return false
|
|
763
869
|
}
|
|
870
|
+
return true
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/// Setting Region Slots to reserver for other 3rd Party SDK to use it
|
|
874
|
+
/// - Parameter slots: Maximum 3 slots allow
|
|
875
|
+
public func setProtectedRegionSlot(slots: Int) throws {
|
|
876
|
+
try self.sdkInstance?.setProtectedRegionSlot(slots)
|
|
877
|
+
self.protectedRegionSlot = slots
|
|
878
|
+
}
|
|
764
879
|
}
|
|
765
880
|
|
|
766
881
|
/// WoosGeofense error
|
|
767
882
|
public struct WoosGeofenceError: Error {
|
|
768
883
|
|
|
769
|
-
|
|
770
|
-
|
|
884
|
+
/// Error info
|
|
885
|
+
let message: String
|
|
771
886
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
887
|
+
/// Initialize
|
|
888
|
+
/// - Parameter message: error detail text
|
|
889
|
+
init(_ message: String) {
|
|
890
|
+
self.message = message
|
|
891
|
+
}
|
|
777
892
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
893
|
+
/// Localized Description
|
|
894
|
+
public var localizedDescription: String {
|
|
895
|
+
return message
|
|
896
|
+
}
|
|
782
897
|
}
|