@woosmap/react-native-plugin-geofencing 1.0.0-beta.1 → 1.0.0-beta.3

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +1 -2
  2. package/README.md +0 -9
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/AbstractPushHelper.java +1 -1
  5. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/AirshipPushHelper.java +1 -1
  6. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosLocationReadyListener.java +1 -1
  7. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosRegionReadyListener.java +1 -1
  8. package/android/src/main/java/com/woosmap/reactnativeplugingeofencing/WoosmapGeofencingTurboModule.java +1025 -0
  9. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosmapGeofencingTurboPackage.java +3 -7
  10. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosmapMessageAndKey.java +2 -3
  11. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosmapTask.java +34 -128
  12. package/android/src/main/java/com/{reactnativeplugingeofencing → woosmap/reactnativeplugingeofencing}/WoosmapUtil.java +1 -1
  13. package/ios/WoosmapGeofenceMessage.swift +1 -0
  14. package/ios/WoosmapGeofencingTurbo.mm +110 -10
  15. package/ios/WoosmapGeofencingTurbo.swift +873 -11
  16. package/lib/commonjs/NativeWoosmapGeofencingTurbo.js +6 -3
  17. package/lib/commonjs/NativeWoosmapGeofencingTurbo.js.map +1 -1
  18. package/lib/commonjs/index.js +37 -131
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/NativeWoosmapGeofencingTurbo.js +6 -3
  21. package/lib/module/NativeWoosmapGeofencingTurbo.js.map +1 -1
  22. package/lib/module/index.js +37 -131
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/typescript/src/NativeWoosmapGeofencingTurbo.d.ts +37 -3
  25. package/lib/typescript/src/NativeWoosmapGeofencingTurbo.d.ts.map +1 -1
  26. package/lib/typescript/src/index.d.ts +3 -3
  27. package/lib/typescript/src/index.d.ts.map +1 -1
  28. package/package.json +2 -1
  29. package/src/NativeWoosmapGeofencingTurbo.ts +109 -0
  30. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +0 -1204
  31. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingPackage.java +0 -28
  32. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapGeofencingTurboModule.java +0 -185
  33. package/ios/PluginGeofencing.mm +0 -123
  34. package/ios/PluginGeofencing.swift +0 -1243
  35. package/lib/commonjs/internal/nativeInterface.js +0 -13
  36. package/lib/commonjs/internal/nativeInterface.js.map +0 -1
  37. package/lib/module/internal/nativeInterface.js +0 -9
  38. package/lib/module/internal/nativeInterface.js.map +0 -1
  39. package/lib/typescript/src/internal/nativeInterface.d.ts +0 -3
  40. package/lib/typescript/src/internal/nativeInterface.d.ts.map +0 -1
  41. /package/ios/{PluginGeofencing-Bridging-Header.h → WoosmapGeofencing-Bridging-Header.h} +0 -0
@@ -1,1243 +0,0 @@
1
- import CoreLocation
2
- import WoosmapGeofencing
3
-
4
- @objc(PluginGeofencing)
5
- class PluginGeofencing: RCTEventEmitter {
6
- /// Location routing to check location permission
7
- private var templocationChecker: CLLocationManager!
8
-
9
- /// List of location watch collected by plugin
10
- private var locationWatchStack: [String: String] = [:]
11
-
12
- /// List of poi watch collected by plugin
13
- private var poiWatchStack: [String: String] = [:]
14
-
15
- /// List all callback collect by Search api call
16
- private var searchAPICallStack: [String: String] = [:]
17
-
18
- /// List all distance watch collected by plugin
19
- private var distanceWatchStack: [String: String] = [:]
20
-
21
- /// List all callback collect by Distance api call
22
- private var distanceAPICallStack: [String: String] = [:]
23
-
24
- /// List all region callback collected by plugin
25
- private var regionWatchStack: [String: String] = [:]
26
-
27
- /// List all visit callback collected by plugin
28
- private var visitWatchStack: [String: String] = [:]
29
-
30
- /// List all airship callback collected by plugin
31
- private var airshipWatchStack: [String: String] = [:]
32
-
33
- /// List all marketing callback collected by plugin.
34
- private var marketingWatchStack: [String: String] = [:]
35
-
36
-
37
- @objc override static func requiresMainQueueSetup() -> Bool {
38
- return true
39
- }
40
-
41
- override func supportedEvents() -> [String]! {
42
- return ["geolocationDidChange",
43
- "geolocationError",
44
- "woosmapgeofenceRegionDidChange",
45
- "woosmapgeofenceRegionError"]
46
- }
47
-
48
- override init() {
49
- super.init()
50
- templocationChecker = CLLocationManager()
51
- templocationChecker.delegate = self
52
- templocationChecker.desiredAccuracy = kCLLocationAccuracyBest
53
- locationWatchStack = [:]
54
- poiWatchStack = [:]
55
- searchAPICallStack = [:]
56
- regionWatchStack = [:]
57
- visitWatchStack = [:]
58
- distanceWatchStack = [:]
59
- distanceAPICallStack = [:]
60
- airshipWatchStack = [:]
61
- marketingWatchStack = [:]
62
- }
63
-
64
- //MARK: Private method
65
- private func showWoosmapError(_ msg: String) -> NSError {
66
- var result: [String: Any] = [:]
67
- result["message"] = msg
68
- let resultError: NSError = NSError(domain: WoosmapGeofenceMessage.plugin_errorDomain, code: WoosmapGeofenceMessage.plugin_errorcode,userInfo: result)
69
- return resultError
70
- }
71
-
72
- @objc(initialize:withResolver:withRejecter:)
73
- func initialize(command: NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
74
-
75
- guard let initParameters = command as? [String: Any] else {
76
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
77
- WoosmapGeofenceMessage.plugin_parsingFailed,
78
- showWoosmapError(WoosmapGeofenceMessage.plugin_parsingFailed))
79
- return
80
- }
81
- var isCallUnsuccessful = false
82
- var privateKeyWoosmapAPI = ""
83
- var isAirshipCallbackEnable: Bool = false
84
- var protectedRegionSlot: Int = -1
85
-
86
-
87
- if let keyProtectedRegionSlot = initParameters["protectedRegionSlot"] as? Int {
88
- if keyProtectedRegionSlot > 3 {
89
- isCallUnsuccessful = true
90
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
91
- WoosmapGeofenceMessage.invalidProtectedRegionSlot,
92
- showWoosmapError(WoosmapGeofenceMessage.invalidProtectedRegionSlot))
93
- }
94
- else{
95
- protectedRegionSlot = keyProtectedRegionSlot
96
- }
97
- }
98
-
99
- if let keyWoosmapAPI = initParameters["privateKeyWoosmapAPI"] as? String {
100
- privateKeyWoosmapAPI = keyWoosmapAPI
101
- }
102
- #if canImport(AirshipKit)
103
- if let keyAirshipPush = initParameters["enableAirshipConnector"] as? Bool {
104
- isAirshipCallbackEnable = keyAirshipPush
105
- }
106
- #endif
107
-
108
- if let trackingProfile = initParameters["trackingProfile"] as? String {
109
- if ConfigurationProfile(rawValue: trackingProfile) != nil {
110
- WoosmapGeofenceService.setup(woosmapKey: privateKeyWoosmapAPI,
111
- configurationProfile: trackingProfile,
112
- airshipTrackingEnable: isAirshipCallbackEnable,
113
- protectedRegionSlot:protectedRegionSlot)
114
-
115
- } else {
116
- isCallUnsuccessful = true
117
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
118
- WoosmapGeofenceMessage.invalidProfile,
119
- showWoosmapError(WoosmapGeofenceMessage.invalidProfile))
120
-
121
- }
122
-
123
- } else {
124
- WoosmapGeofenceService.setup(woosmapKey: privateKeyWoosmapAPI,
125
- configurationProfile: "",
126
- airshipTrackingEnable: isAirshipCallbackEnable,
127
- protectedRegionSlot: protectedRegionSlot)
128
- }
129
- if(isCallUnsuccessful == false){
130
- resolve(WoosmapGeofenceMessage.initialize)
131
- }
132
- }
133
-
134
-
135
- @objc(getPermissionsStatus:withRejecter:)
136
- func getPermissionsStatus(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
137
- let authorizationStatus: CLAuthorizationStatus
138
- if #available(iOS 14, *) {
139
- let manager = CLLocationManager()
140
- authorizationStatus = manager.authorizationStatus
141
- } else {
142
- authorizationStatus = CLLocationManager.authorizationStatus()
143
- }
144
- var str: String = "UNKNOWN"
145
- switch authorizationStatus {
146
- case .denied:
147
- str = "DENIED"
148
- case .restricted:
149
- str = "DENIED"
150
- case .authorizedAlways:
151
- str = "GRANTED_BACKGROUND"
152
- case .authorizedWhenInUse:
153
- str = "GRANTED_FOREGROUND"
154
- default:
155
- str = "UNKNOWN"
156
- }
157
- resolve(str)
158
- }
159
-
160
- /// Updating new woosmap key
161
- /// - Parameter command: -
162
- // implemented in turbo (WoosmapGeofencingTurbo)
163
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
164
- @objc(setWoosmapApiKey:withResolver:withRejecter:)
165
- func setWoosmapApiKey(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
166
-
167
- if let woosmapkey = command[0] as? String {
168
- if WoosmapGeofenceService.shared != nil {
169
- do {
170
- try WoosmapGeofenceService.shared?.setWoosmapAPIKey(key: woosmapkey)
171
- resolve(WoosmapGeofenceMessage.initialize)
172
- } catch let error as WoosGeofenceError {
173
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
174
- error.localizedDescription,
175
- showWoosmapError(error.localizedDescription))
176
- } catch {
177
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
178
- error.localizedDescription,
179
- showWoosmapError(error.localizedDescription))
180
- }
181
- } else {
182
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
183
- WoosmapGeofenceMessage.woosmapNotInitialized,
184
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
185
- }
186
- } else {
187
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
188
- WoosmapGeofenceMessage.invalidWoosmapKey,
189
- showWoosmapError(WoosmapGeofenceMessage.invalidWoosmapKey))
190
- }
191
- }
192
-
193
- @objc(startTracking:withResolver:withRejecter:)
194
- func startTracking(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
195
-
196
- if let profileName = command[0] as? String {
197
- if WoosmapGeofenceService.shared != nil {
198
- do {
199
- try WoosmapGeofenceService.shared?.startTracking(profile: profileName)
200
- resolve(WoosmapGeofenceMessage.initialize)
201
- } catch let error as WoosGeofenceError {
202
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
203
- error.localizedDescription,
204
- showWoosmapError(error.localizedDescription))
205
- } catch {
206
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
207
- error.localizedDescription,
208
- showWoosmapError(error.localizedDescription))
209
- }
210
- } else {
211
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
212
- WoosmapGeofenceMessage.woosmapNotInitialized,
213
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
214
- }
215
- } else {
216
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
217
- WoosmapGeofenceMessage.invalidWoosmapKey,
218
- showWoosmapError(WoosmapGeofenceMessage.invalidWoosmapKey))
219
- }
220
- }
221
-
222
- /// Stop woosgeolocationservice
223
- /// - Parameter command: -
224
-
225
-
226
- /// Stop woosgeolocationservice
227
- /// - Parameters:
228
- /// - resolve: return message on sucessfull call
229
- /// - reject: never called but to manage compatiblity with android promise it is part of plugin
230
- @objc(stopTracking:withRejecter:)
231
- func stopTracking (resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
232
- if WoosmapGeofenceService.shared != nil {
233
- WoosmapGeofenceService.shared?.stopTracking()
234
- resolve(WoosmapGeofenceMessage.initialize)
235
- }
236
- else{
237
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
238
- WoosmapGeofenceMessage.woosmapNotInitialized,
239
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
240
- }
241
- }
242
-
243
- /// Showing location permission popup on screen
244
- /// - Parameters:
245
- /// - command: background mode true for background access and false for forground access
246
- /// - resolve: return message on sucessfull call
247
- /// - reject: return error on function call
248
- @objc(requestPermissions:withResolver:withRejecter:)
249
- func requestPermissions(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock){
250
- // The requestAlwaysAuthorization will show prompt only for the first time. From then onwards, no prompts are shown.
251
- // https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization
252
-
253
- if let backgoundMode = command[0] as? Bool {
254
- let status = CLLocationManager().authorizationStatus
255
-
256
- if backgoundMode {
257
- if status == .notDetermined {
258
- self.templocationChecker.requestAlwaysAuthorization()
259
- } else if status == .authorizedAlways {
260
- resolve(WoosmapGeofenceMessage.samePermission)
261
- } else {
262
- resolve(WoosmapGeofenceMessage.showingPermissionBox)
263
- Task { @MainActor in
264
- let appname: String = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? ""
265
- var alertInfo: String = ""
266
- if status == .denied {
267
- alertInfo = String(format: WoosmapGeofenceMessage.deniedPermission, appname)
268
- } else {
269
- alertInfo = String(format: WoosmapGeofenceMessage.replacePermission, appname)
270
- }
271
- let alert = UIAlertController(title: "", message: alertInfo, preferredStyle: UIAlertController.Style.alert)
272
- alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.cancel, style: UIAlertAction.Style.default, handler: nil))
273
- alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.setting, style: UIAlertAction.Style.default, handler: { _ in
274
- if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
275
- UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
276
- }
277
- }))
278
- var rootViewController = UIApplication.shared.topViewController //keyWindow?.rootViewController
279
- if let navigationController = rootViewController as? UINavigationController {
280
- rootViewController = navigationController.viewControllers.first
281
- }
282
- if let tabBarController = rootViewController as? UITabBarController {
283
- rootViewController = tabBarController.selectedViewController
284
- }
285
- rootViewController?.present(alert, animated: true, completion: nil)
286
- }
287
- }
288
- } else {
289
- if status == .notDetermined {
290
- self.templocationChecker.requestWhenInUseAuthorization()
291
- } else if status == .authorizedWhenInUse {
292
- resolve(WoosmapGeofenceMessage.samePermission)
293
- } else {
294
- resolve(WoosmapGeofenceMessage.showingPermissionBox)
295
- Task { @MainActor in
296
- let appname: String = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? ""
297
- var alertInfo: String = ""
298
- if status == .denied {
299
- alertInfo = String(format: WoosmapGeofenceMessage.deniedPermission, appname)
300
- } else {
301
- alertInfo = String(format: WoosmapGeofenceMessage.replacePermission, appname)
302
- }
303
- let alert = UIAlertController(title: "", message: alertInfo, preferredStyle: UIAlertController.Style.alert)
304
- alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.cancel, style: UIAlertAction.Style.default, handler: nil))
305
- alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.setting, style: UIAlertAction.Style.default, handler: { _ in
306
- if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
307
- UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
308
- }
309
- }))
310
- var rootViewController = UIApplication.shared.topViewController// keyWindow?.rootViewController
311
- if let navigationController = rootViewController as? UINavigationController {
312
- rootViewController = navigationController.viewControllers.first
313
- }
314
- if let tabBarController = rootViewController as? UITabBarController {
315
- rootViewController = tabBarController.selectedViewController
316
- }
317
- rootViewController?.present(alert, animated: true, completion: nil)
318
- }
319
-
320
- }
321
-
322
- }
323
-
324
- }
325
- }
326
-
327
-
328
-
329
- /// Adding Location watch
330
- /// - Parameters:
331
- /// - watchid: Reference Watch ID
332
- /// - resolve: return reference watchid on successfully call
333
- /// - reject: return error info
334
- @objc(watchLocation:withResolver:withRejecter:)
335
- func watchLocation(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
336
- if WoosmapGeofenceService.shared != nil {
337
- locationWatchStack[watchid] = watchid
338
- if locationWatchStack.count == 1 {
339
- NotificationCenter.default.addObserver(
340
- self,
341
- selector: #selector(newLocationAdded(_:)),
342
- name: .newLocationSaved,
343
- object: nil)
344
- }
345
- resolve(watchid)
346
- } else {
347
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
348
- WoosmapGeofenceMessage.woosmapNotInitialized,
349
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
350
- }
351
-
352
- }
353
-
354
-
355
- /// Clear location watch for given id
356
- /// - Parameters:
357
- /// - watchid: Reference to clear watch
358
- /// - resolve: return Reference watchid on successfully call
359
- /// - reject: return error info
360
- @objc(clearLocationWatch:withResolver:withRejecter:)
361
- func clearLocationWatch(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
362
-
363
- if let _ = locationWatchStack[watchid] {
364
- locationWatchStack.removeValue(forKey: watchid)
365
- }
366
- if locationWatchStack.count == 0 {
367
- // remove delegate watch
368
- NotificationCenter.default.removeObserver(self, name: .newLocationSaved, object: nil)
369
- }
370
- resolve(watchid)
371
- }
372
-
373
- /// Clear all location callback
374
- /// - Parameters:
375
- /// - resolve: return Reference watchid on successfully call
376
- /// - reject: return error info
377
- @objc(clearAllLocationWatch:withRejecter:)
378
- func clearAllLocationWatch(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
379
- locationWatchStack.removeAll()
380
- if locationWatchStack.count == 0 {
381
- // remove delegate watch
382
- NotificationCenter.default.removeObserver(self, name: .newLocationSaved, object: nil)
383
- }
384
- resolve("00000-00000-0000")
385
- }
386
-
387
-
388
- /// Adding Region watch
389
- /// - Parameters:
390
- /// - watchid: Reference Watch ID
391
- /// - resolve: return reference watchid on successfully call
392
- /// - reject: return error info
393
- @objc(watchRegions:withResolver:withRejecter:)
394
- func watchRegions(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
395
- if WoosmapGeofenceService.shared != nil {
396
- regionWatchStack[watchid] = watchid
397
- if regionWatchStack.count == 1 {
398
- NotificationCenter.default.addObserver(
399
- self,
400
- selector: #selector(didEventPOIRegion(_:)),
401
- name: .didEventPOIRegion,
402
- object: nil)
403
- }
404
- resolve(watchid)
405
- } else {
406
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
407
- WoosmapGeofenceMessage.woosmapNotInitialized,
408
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
409
- }
410
-
411
- }
412
-
413
- /// Clear Region watch for given id
414
- /// - Parameters:
415
- /// - watchid: Reference to clear watch
416
- /// - resolve: return Reference watchid on successfully call
417
- /// - reject: return error info
418
- @objc(clearRegionsWatch:withResolver:withRejecter:)
419
- func clearRegionsWatch(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
420
-
421
- if let _ = regionWatchStack[watchid] {
422
- regionWatchStack.removeValue(forKey: watchid)
423
- }
424
- if regionWatchStack.count == 0 {
425
- // remove delegate watch
426
- NotificationCenter.default.removeObserver(self, name: .didEventPOIRegion, object: nil)
427
- }
428
- resolve(watchid)
429
- }
430
-
431
- /// Clear all region callback
432
- /// - Parameters:
433
- /// - resolve: return Reference watchid on successfully call
434
- /// - reject: return error info
435
- @objc(clearAllRegionsWatch:withRejecter:)
436
- func clearAllRegionsWatch(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
437
- regionWatchStack.removeAll()
438
- if regionWatchStack.count == 0 {
439
- // remove delegate watch
440
- NotificationCenter.default.removeObserver(self, name: .didEventPOIRegion, object: nil)
441
- }
442
- resolve("00000-00000-0000")
443
- }
444
-
445
-
446
- /// Add a region that you want to monitor. Method will accept an object with the following attributes:
447
- /// regionId - Id of the region
448
- /// lat - Latitude
449
- /// lng - Longitude
450
- /// radius - Radius in meters
451
- /// type - circle/isochrone
452
- /// - Parameters:
453
- /// - regioninfo: regioninfo description
454
- /// - resolve: return Reference watchid on successfully call
455
- /// - reject: return error info
456
- // implemented in turbo (WoosmapGeofencingTurbo)
457
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
458
- @objc(addRegion:withResolver:withRejecter:)
459
- func addRegion(regioninfo:NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
460
- if let woosService = WoosmapGeofenceService.shared {
461
- if let regioninfo = regioninfo as? [String: Any] {
462
- var regionid = UUID().uuidString
463
- var radius = 100
464
- var lat: Double = 0
465
- var lng: Double = 0
466
- var regiontype:String = ""
467
- if let inputregionId = regioninfo["regionId"] as? String {
468
- regionid = inputregionId
469
- }
470
- if let inputCoordinate = regioninfo["lat"] as? String {
471
- lat = Double(inputCoordinate) ?? 0
472
- } else if let inputCoordinate = regioninfo["lat"] as? Double {
473
- lat = inputCoordinate
474
- }
475
- if let inputCoordinate = regioninfo["lng"] as? String {
476
- lng = Double(inputCoordinate) ?? 0
477
- } else if let inputCoordinate = regioninfo["lng"] as? Double {
478
- lng = inputCoordinate
479
- }
480
- if let inputradius = regioninfo["radius"] as? String {
481
- radius = Int(inputradius) ?? 0
482
- } else if let inputradius = regioninfo["radius"] as? Int {
483
- radius = inputradius
484
- }
485
-
486
- if let inputtype = regioninfo["type"] as? String {
487
- regiontype = inputtype
488
- }
489
-
490
- if lat == 0 || lng == 0 {
491
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
492
- WoosmapGeofenceMessage.invalidLocation,
493
- showWoosmapError(WoosmapGeofenceMessage.invalidLocation))
494
- } else if !(regiontype == "circle" || regiontype == "isochrone") {
495
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
496
- WoosmapGeofenceMessage.invalidRegionType,
497
- showWoosmapError(WoosmapGeofenceMessage.invalidRegionType))
498
- } else {
499
- if(woosService.isSearviceActive()){
500
- let coordinate: CLLocationCoordinate2D = CLLocationCoordinate2D.init(latitude: lat, longitude: lng)
501
- let (regionIsCreated, identifier) = woosService.addRegion(identifier: regionid, center: coordinate, radius: radius, type: regiontype)
502
- var result: [AnyHashable: Any] = [:]
503
- result["regionid"] = identifier
504
- result["iscreated"] = regionIsCreated
505
- if(regionIsCreated) {
506
- resolve(result["regionid"])
507
- }
508
- else{
509
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
510
- WoosmapGeofenceMessage.regionInfoDuplicateID,
511
- showWoosmapError(WoosmapGeofenceMessage.regionInfoDuplicateID))
512
- }
513
- }
514
- else{
515
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
516
- WoosmapGeofenceMessage.woosmapProfilNotActivated,
517
- showWoosmapError(WoosmapGeofenceMessage.woosmapProfilNotActivated))
518
- }
519
- }
520
- } else {
521
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
522
- WoosmapGeofenceMessage.regionInfoEmptyOrNull,
523
- showWoosmapError(WoosmapGeofenceMessage.regionInfoEmptyOrNull))
524
- }
525
-
526
- } else {
527
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
528
- WoosmapGeofenceMessage.woosmapNotInitialized,
529
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
530
- }
531
- }
532
-
533
- /// Added SFMC Credentials to SDK
534
- /// - Parameters:
535
- /// - credentials: SFMC Credentials object
536
- /// - resolve: return Reference watchid on successfully call
537
- /// - reject: return error info
538
- @objc(setSFMCCredentials:withResolver:withRejecter:)
539
- func setSFMCCredentials (credentials: NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
540
- if WoosmapGeofenceService.shared != nil {
541
- if let credentials = credentials as? [String: String] {
542
- do {
543
- try WoosmapGeofenceService.shared?.setSFMCCredentials(credentials: credentials)
544
- resolve(WoosmapGeofenceMessage.initialize)
545
- } catch let error as WoosGeofenceError {
546
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
547
- error.localizedDescription,
548
- showWoosmapError(error.localizedDescription))
549
- } catch {
550
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
551
- error.localizedDescription,
552
- showWoosmapError(error.localizedDescription))
553
- }
554
- } else {
555
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
556
- WoosmapGeofenceMessage.invalidSFMCCredentials,
557
- showWoosmapError(WoosmapGeofenceMessage.invalidSFMCCredentials))
558
- }
559
- } else {
560
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
561
- WoosmapGeofenceMessage.woosmapNotInitialized,
562
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
563
- }
564
- }
565
-
566
- /// you create a geofence around a POI, manually define the radius value (100.0) or choose the user_properties subfield that corresponds to radius value of the geofence ("radiusPOI").
567
- /// - Parameters:
568
- /// - radius: radius enum or number in meters
569
- /// - resolve: return Ok on successfully call
570
- /// - reject: return error info
571
- // implemented in turbo (WoosmapGeofencingTurbo)
572
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
573
- @objc(setPoiRadius:withResolver:withRejecter:)
574
- func setPoiRadius (radius: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
575
- if WoosmapGeofenceService.shared != nil {
576
- var userInputRadiusValue: String = ""
577
- if let radius = Int32(radius) {
578
- userInputRadiusValue = String(radius)
579
- }
580
- else if let radius = Double(radius) {
581
- userInputRadiusValue = String(radius)
582
- }
583
- else{
584
- userInputRadiusValue = radius
585
- }
586
-
587
- if(userInputRadiusValue != ""){
588
- WoosmapGeofenceService.shared?.setPoiRadius(radius: userInputRadiusValue)
589
- resolve(WoosmapGeofenceMessage.initialize)
590
-
591
- } else {
592
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
593
- WoosmapGeofenceMessage.invalidPOIRadius,
594
- showWoosmapError(WoosmapGeofenceMessage.invalidPOIRadius))
595
- }
596
- } else {
597
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
598
- WoosmapGeofenceMessage.woosmapNotInitialized,
599
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
600
- }
601
- }
602
-
603
- /// Fetch All region
604
- /// - Parameters:
605
- /// - resolve: return list of Array with region info
606
- /// - reject: return error info
607
- // implemented in turbo (WoosmapGeofencingTurbo — getRegions handles all + single)
608
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
609
- @objc(getAllRegions:withRejecter:)
610
- func getAllRegions(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
611
- if let objWoos = WoosmapGeofenceService.shared {
612
- let capturedRegions = objWoos.getRegions()
613
- var result: [[AnyHashable: Any]] = []
614
-
615
- for item in capturedRegions {
616
- result.append(formatRegionData(woosdata: item))
617
- }
618
- resolve(result);
619
- } else {
620
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
621
- WoosmapGeofenceMessage.woosmapNotInitialized,
622
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
623
- }
624
- }
625
-
626
- /// Fetch region
627
- /// - Parameters:
628
- /// - regionid: regionid to fetch
629
- /// - resolve: return region info
630
- /// - reject: error info
631
- // implemented in turbo (WoosmapGeofencingTurbo)
632
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
633
- @objc(getRegions:withResolver:withRejecter:)
634
- func getRegions(regionid:String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
635
- if let objWoos = WoosmapGeofenceService.shared {
636
- if(regionid != ""){
637
- if let capturedRegions = objWoos.getRegions(id:regionid){
638
- resolve(formatRegionData(woosdata: capturedRegions));
639
- }
640
- else{
641
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
642
- WoosmapGeofenceMessage.notfound_regionid,
643
- showWoosmapError(WoosmapGeofenceMessage.notfound_regionid))
644
- }
645
- }
646
- else{
647
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
648
- WoosmapGeofenceMessage.required_regionid,
649
- showWoosmapError(WoosmapGeofenceMessage.required_regionid))
650
- }
651
-
652
- } else {
653
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
654
- WoosmapGeofenceMessage.woosmapNotInitialized,
655
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
656
- }
657
- }
658
-
659
- /// Clear All regions from DB
660
- /// - Parameters:
661
- /// - resolve: return regionDeleted
662
- /// - reject: error info
663
- // implemented in turbo (WoosmapGeofencingTurbo)
664
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
665
- @objc(removeAllRegions:withRejecter:)
666
- func removeAllRegions(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
667
- if let objWoos = WoosmapGeofenceService.shared {
668
- objWoos.deleteAllRegion()
669
- resolve(WoosmapGeofenceMessage.regionDeleted);
670
- } else {
671
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
672
- WoosmapGeofenceMessage.woosmapNotInitialized,
673
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
674
- }
675
- }
676
-
677
- /// Remove region with ID
678
- /// - Parameters:
679
- /// - regionid: region id
680
- /// - resolve: return regionDeleted
681
- /// - reject: error info
682
- // implemented in turbo (WoosmapGeofencingTurbo)
683
- @available(*, deprecated, message: "Implemented in the WoosmapGeofencingTurbo TurboModule")
684
- @objc(removeRegion:withResolver:withRejecter:)
685
- func removeRegion(regionid:String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
686
- if let objWoos = WoosmapGeofenceService.shared {
687
- if(regionid != ""){
688
- do{
689
- try objWoos.deleteRegions(id: regionid)
690
- resolve(WoosmapGeofenceMessage.regionDeleted);
691
- }
692
- catch let error as WoosGeofenceError {
693
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
694
- error.localizedDescription,
695
- showWoosmapError(error.localizedDescription))
696
- } catch {
697
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
698
- error.localizedDescription,
699
- showWoosmapError(error.localizedDescription))
700
- }
701
- }
702
- else{
703
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
704
- WoosmapGeofenceMessage.required_regionid,
705
- showWoosmapError(WoosmapGeofenceMessage.required_regionid))
706
- }
707
-
708
- } else {
709
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
710
- WoosmapGeofenceMessage.woosmapNotInitialized,
711
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
712
- }
713
- }
714
-
715
- /// Fetch all locations
716
- /// - Parameters:
717
- /// - resolve: List of Array with location info
718
- /// - reject: error info
719
- @objc(getAllLocations:withRejecter:)
720
- func getAllLocations(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
721
- if let objWoos = WoosmapGeofenceService.shared {
722
- let capturedLocations = objWoos.getLocations()
723
- var result: [[AnyHashable: Any]] = []
724
-
725
- for item in capturedLocations {
726
- result.append(formatLocationData(woosdata: item))
727
- }
728
- resolve(result);
729
- } else {
730
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
731
- WoosmapGeofenceMessage.woosmapNotInitialized,
732
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
733
- }
734
- }
735
-
736
- /// Fetch Location info for given id
737
- /// - Parameters:
738
- /// - locationid: id of location
739
- /// - resolve: Location info
740
- /// - reject: Error Info
741
- @objc(getLocation:withResolver:withRejecter:)
742
- func getLocation(locationid:String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
743
- if let objWoos = WoosmapGeofenceService.shared {
744
- if(locationid != ""){
745
- if let capturedPOIs = objWoos.getLocations(id:locationid){
746
- resolve(formatLocationData(woosdata: capturedPOIs));
747
- }
748
- else{
749
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
750
- WoosmapGeofenceMessage.notfound_locationid,
751
- showWoosmapError(WoosmapGeofenceMessage.notfound_locationid))
752
- }
753
- }
754
- else{
755
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
756
- WoosmapGeofenceMessage.required_regionid,
757
- showWoosmapError(WoosmapGeofenceMessage.required_regionid))
758
- }
759
-
760
- } else {
761
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
762
- WoosmapGeofenceMessage.woosmapNotInitialized,
763
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
764
- }
765
- }
766
-
767
- /// Get All Pois
768
- /// - Parameters:
769
- /// - resolve: List of Array of POI info
770
- /// - reject: Error info
771
- @objc(getAllPois:withRejecter:)
772
- func getAllPois(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
773
- if let objWoos = WoosmapGeofenceService.shared {
774
- let capturedRegions = objWoos.getPOIs()
775
- var result: [[AnyHashable: Any]] = []
776
- for item in capturedRegions {
777
- result.append(formatPOIData(woosdata: item))
778
- }
779
- resolve(result);
780
- } else {
781
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
782
- WoosmapGeofenceMessage.woosmapNotInitialized,
783
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
784
- }
785
- }
786
-
787
- /// Get POI info by ID
788
- /// - Parameters:
789
- /// - poiid: id of POI
790
- /// - resolve: POI info
791
- /// - reject: Error Info
792
- @objc(getPoi:withResolver:withRejecter:)
793
- func getPoi(poiid:String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
794
- if let objWoos = WoosmapGeofenceService.shared {
795
- if(poiid != ""){
796
- if let capturedRegions = objWoos.getPOIs(id:poiid){
797
- resolve(formatPOIData(woosdata: capturedRegions));
798
- }
799
- else{
800
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
801
- WoosmapGeofenceMessage.notfound_poiid,
802
- showWoosmapError(WoosmapGeofenceMessage.notfound_poiid))
803
- }
804
- }
805
- else{
806
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
807
- WoosmapGeofenceMessage.required_poiid,
808
- showWoosmapError(WoosmapGeofenceMessage.required_poiid))
809
- }
810
-
811
- } else {
812
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
813
- WoosmapGeofenceMessage.woosmapNotInitialized,
814
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
815
- }
816
- }
817
-
818
- /// Clear all Location from DB
819
- /// - Parameters:
820
- /// - resolve: Deleted
821
- /// - reject: Error Info
822
- @objc(removeAllLocations:withRejecter:)
823
- func removeAllLocations(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
824
- if let objWoos = WoosmapGeofenceService.shared {
825
- objWoos.deleteAllLocations()
826
- resolve(WoosmapGeofenceMessage.locationDeleted);
827
- } else {
828
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
829
- WoosmapGeofenceMessage.woosmapNotInitialized,
830
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
831
- }
832
- }
833
-
834
- /// Clear all POIs from DB
835
- /// - Parameters:
836
- /// - resolve: Deleted
837
- /// - reject: Error Info
838
- @objc(removeAllPois:withRejecter:)
839
- func removeAllPois(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
840
- if let objWoos = WoosmapGeofenceService.shared {
841
- objWoos.deletePOI()
842
- resolve(WoosmapGeofenceMessage.poiDeleted);
843
- } else {
844
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
845
- WoosmapGeofenceMessage.woosmapNotInitialized,
846
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
847
- }
848
- }
849
-
850
- // MARK: Custom Tracking
851
-
852
- /// Start User defined tracking
853
- /// - Parameters:
854
- /// - mode: local/external
855
- /// - source: URL or from local resource
856
- /// - resolve: Success
857
- /// - reject: Error Info
858
- @objc(startCustomTracking:source:withResolver:withRejecter:)
859
- func startCustomTracking(mode:String,
860
- source:String,
861
- resolve:@escaping RCTPromiseResolveBlock,
862
- reject:@escaping RCTPromiseRejectBlock) {
863
- if let objWoos = WoosmapGeofenceService.shared {
864
- objWoos.startCustomTracking(mode: mode, source: source, completion: { Value, Error in
865
- if let functionError = Error{
866
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
867
- functionError.localizedDescription,
868
- self.showWoosmapError(functionError.localizedDescription))
869
- }
870
- else{
871
- if(Value){
872
- resolve(WoosmapGeofenceMessage.initialize);
873
- }
874
- }
875
- });
876
- } else {
877
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
878
- WoosmapGeofenceMessage.woosmapNotInitialized,
879
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
880
- }
881
- }
882
-
883
- /// Fetch Indoor Beacons
884
- /// - Parameters:
885
- /// - resolve: return list of Array with region info
886
- /// - reject: return error info
887
- @objc(getAllIndoorBeacons:withRejecter:)
888
- func getAllIndoorBeacons(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
889
- if let objWoos = WoosmapGeofenceService.shared {
890
- let capturedRegions = objWoos.getIndoorBeacons(id: nil) ?? []
891
- var result: [[AnyHashable: Any]] = []
892
- for item in capturedRegions {
893
- result.append(formatIndoorBeaconPOIData(woosdata: item))
894
- }
895
- resolve(result);
896
- } else {
897
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
898
- WoosmapGeofenceMessage.woosmapNotInitialized,
899
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
900
- }
901
- }
902
-
903
- /// Get Indoor beacon info by venueID
904
- /// - Parameters:
905
- /// - venueID: id of venue
906
- /// - resolve: beacon info
907
- /// - reject: Error Info
908
- @objc(getIndoorBeacons:withResolver:withRejecter:)
909
- func getIndoorBeacons(venueID:String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
910
- if let objWoos = WoosmapGeofenceService.shared {
911
-
912
- if(venueID != ""){
913
- if let capturedRegions = objWoos.getIndoorBeacons(id:venueID){
914
- var result: [[AnyHashable: Any]] = []
915
- for item in capturedRegions {
916
- result.append(formatIndoorBeaconPOIData(woosdata: item))
917
- }
918
- resolve(result);
919
- }
920
- else{
921
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
922
- WoosmapGeofenceMessage.notfound_poiid,
923
- showWoosmapError(WoosmapGeofenceMessage.notfound_venueid))
924
- }
925
- }
926
- else{
927
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
928
- WoosmapGeofenceMessage.required_poiid,
929
- showWoosmapError(WoosmapGeofenceMessage.required_venueid))
930
- }
931
-
932
- } else {
933
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
934
- WoosmapGeofenceMessage.woosmapNotInitialized,
935
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
936
- }
937
- }
938
-
939
- /// Clear all Indoor beacons from DB
940
- /// - Parameters:
941
- /// - resolve: Deleted
942
- /// - reject: Error Info
943
- @objc(removeIndoorBeacons:withRejecter:)
944
- func removeIndoorBeacons(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
945
- if let objWoos = WoosmapGeofenceService.shared {
946
- objWoos.deleteIndoorBeacons()
947
- resolve(WoosmapGeofenceMessage.locationDeleted);
948
- } else {
949
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
950
- WoosmapGeofenceMessage.woosmapNotInitialized,
951
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
952
- }
953
- }
954
-
955
- /// Refresh POI data from server
956
- /// - Parameters:
957
- /// - resolve: OK
958
- /// - reject: Error Info
959
- @objc(refreshPois:withRejecter:)
960
- func refreshPois(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
961
- if let objWoos = WoosmapGeofenceService.shared {
962
- objWoos.refreshPOI()
963
- resolve(WoosmapGeofenceMessage.refreshPOIStatus);
964
- } else {
965
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
966
- WoosmapGeofenceMessage.woosmapNotInitialized,
967
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
968
- }
969
- }
970
-
971
-
972
- /// Free up region slots to use for any third party SDK . Maximum 3 slots allows
973
- /// - Parameters:
974
- /// - slots: Max 3 slots allow
975
- /// - resolve: return Ok on successfully call
976
- /// - reject: return error info
977
- @objc(setProtectedRegionSlot:withResolver:withRejecter:)
978
- func setProtectedRegionSlot (slots: NSNumber, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
979
- if WoosmapGeofenceService.shared != nil {
980
- do {
981
- try WoosmapGeofenceService.shared?.setProtectedRegionSlot(slots: slots.intValue)
982
- resolve(WoosmapGeofenceMessage.initialize)
983
- } catch {
984
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
985
- WoosmapGeofenceMessage.invalidProtectedRegionSlot,
986
- showWoosmapError(WoosmapGeofenceMessage.invalidProtectedRegionSlot))
987
-
988
- }
989
- } else {
990
- reject(WoosmapGeofenceMessage.plugin_errorDomain,
991
- WoosmapGeofenceMessage.woosmapNotInitialized,
992
- showWoosmapError(WoosmapGeofenceMessage.woosmapNotInitialized))
993
- }
994
- }
995
-
996
- // MARK: Events
997
- @objc func newLocationAdded(_ notification: Notification) {
998
- if let location = notification.userInfo?["Location"] as? Location {
999
- if(locationWatchStack.count>0){
1000
- sendEvent(withName: "geolocationDidChange", body: formatLocationData(woosdata:location))
1001
- }
1002
- }
1003
- }
1004
-
1005
- @objc func didEventPOIRegion(_ notification: Notification) {
1006
- if let region = notification.userInfo?["Region"] as? Region {
1007
- sendEvent(withName: "woosmapgeofenceRegionDidChange", body: formatRegionData(woosdata:region))
1008
- }
1009
- }
1010
-
1011
- // MARK: Supporting functions
1012
-
1013
- private func formatIndoorBeaconPOIData(woosdata: IndoorBeacon) -> [AnyHashable: Any] {
1014
- var result: [AnyHashable: Any] = [:]
1015
- result["identifier"] = woosdata.identifier
1016
- result["properties"] = woosdata.properties
1017
- result["latitude"] = woosdata.latitude
1018
- result["longitude"] = woosdata.longitude
1019
- result["venueId"] = woosdata.venue_id
1020
- result["major"] = woosdata.Major
1021
- result["minor"] = woosdata.Minor
1022
- result["beaconId"] = woosdata.BeaconID
1023
- result["date"] = woosdata.date.timeIntervalSince1970 * 1000
1024
- return result
1025
- }
1026
-
1027
- private func formatLocationData(woosdata: Location) -> [AnyHashable: Any] {
1028
- var result: [AnyHashable: Any] = [:]
1029
- if let date = woosdata.date {
1030
- result["date"] = date.timeIntervalSince1970 * 1000
1031
- } else {
1032
- result["date"] = 0
1033
- }
1034
- result["latitude"] = woosdata.latitude
1035
- result["locationdescription"] = woosdata.locationDescription
1036
- result["locationid"] = woosdata.locationId
1037
- result["longitude"] = woosdata.longitude
1038
- return result
1039
- }
1040
- private func formatPOIData(woosdata: POI) -> [AnyHashable: Any] {
1041
- var result: [AnyHashable: Any] = [:]
1042
- if let data = woosdata.jsonData {
1043
- do {
1044
- let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
1045
- result["jsondata"] = json
1046
- } catch { print("Invalid JSON format") }
1047
- }
1048
- result["city"] = woosdata.city
1049
- result["idstore"] = woosdata.idstore
1050
- result["name"] = woosdata.name
1051
- if let date = woosdata.date {
1052
- result["date"] = date.timeIntervalSince1970 * 1000
1053
- } else {
1054
- result["date"] = 0
1055
- }
1056
- result["distance"] = woosdata.distance
1057
- result["duration"] = woosdata.duration ?? "-"
1058
- result["latitude"] = woosdata.latitude
1059
- result["locationid"] = woosdata.locationId
1060
- result["longitude"] = woosdata.longitude
1061
- result["zipcode"] = woosdata.zipCode
1062
- result["radius"] = woosdata.radius
1063
- result["address"] = woosdata.address
1064
- result["countrycode"] = woosdata.countryCode
1065
- result["tags"] = woosdata.tags
1066
- result["types"] = woosdata.types
1067
- result["contact"] = woosdata.contact
1068
- result["userProperties"] = woosdata.user_properties
1069
- result["openNow"] = woosdata.openNow
1070
- return result
1071
- }
1072
- private func formatZOIData(woosdata: ZOI) -> [AnyHashable: Any] {
1073
- var result: [AnyHashable: Any] = [:]
1074
- result["accumulator"] = woosdata.accumulator
1075
- result["age"] = woosdata.age
1076
- result["covariance_det"] = woosdata.covariance_det
1077
- result["duration"] = woosdata.duration
1078
- if let date = woosdata.endTime {
1079
- result["endtime"] = date.timeIntervalSince1970 * 1000
1080
- } else {
1081
- result["endtime"] = 0
1082
- }
1083
- result["idvisits"] = woosdata.idVisits
1084
- result["latmean"] = woosdata.latMean
1085
- result["lngmean"] = woosdata.lngMean
1086
- result["period"] = woosdata.period
1087
- result["prior_probability"] = woosdata.prior_probability
1088
- result["starttime"] = woosdata.startTime
1089
- result["weekly_density"] = woosdata.weekly_density
1090
- result["wktpolygon"] = woosdata.wktPolygon
1091
- result["x00covariance_matrix_inverse"] = woosdata.x00Covariance_matrix_inverse
1092
- result["x01covariance_matrix_inverse"] = woosdata.x01Covariance_matrix_inverse
1093
- result["x10covariance_matrix_inverse"] = woosdata.x10Covariance_matrix_inverse
1094
- result["x11covariance_matrix_inverse"] = woosdata.x11Covariance_matrix_inverse
1095
- return result
1096
- }
1097
- private func formatVisitData(woosdata: Visit) -> [AnyHashable: Any] {
1098
- var result: [AnyHashable: Any] = [:]
1099
- result["accuracy"] = woosdata.accuracy
1100
- if let date = woosdata.date {
1101
- result["date"] = date.timeIntervalSince1970 * 1000
1102
- } else {
1103
- result["date"] = 0
1104
- }
1105
- if let date = woosdata.arrivalDate {
1106
- result["arrivaldate"] = date.timeIntervalSince1970 * 1000
1107
- } else {
1108
- result["arrivaldate"] = 0
1109
- }
1110
- if let date = woosdata.departureDate {
1111
- result["departuredate"] = date.timeIntervalSince1970 * 1000
1112
- } else {
1113
- result["departuredate"] = 0
1114
- }
1115
- result["latitude"] = woosdata.latitude
1116
- result["longitude"] = woosdata.longitude
1117
- return result
1118
- }
1119
- private func formatRegionData(woosdata: Region) -> [AnyHashable: Any] {
1120
- var result: [AnyHashable: Any] = [:]
1121
- result["date"] = woosdata.date.timeIntervalSince1970 * 1000
1122
- // if let date = woosdata.date {
1123
- // result["date"] = date.timeIntervalSince1970 * 1000
1124
- // } else {
1125
- // result["date"] = 0
1126
- // }
1127
- result["didenter"] = woosdata.didEnter
1128
- result["identifier"] = woosdata.identifier
1129
- result["latitude"] = woosdata.latitude
1130
- result["longitude"] = woosdata.longitude
1131
- result["radius"] = woosdata.radius
1132
- result["frompositiondetection"] = woosdata.fromPositionDetection
1133
- result["eventname"] = woosdata.eventName
1134
- result["spenttime"] = woosdata.spentTime
1135
- return result
1136
- }
1137
-
1138
- private func formatDistanceData(woosdata: DistanceResponseResult) -> [AnyHashable: Any] {
1139
- var result: [AnyHashable: Any] = [:]
1140
- result["locationid"] = ""//woosdata.locationId
1141
- result["distance"] = String(woosdata.distance)
1142
- result["duration"] = String(woosdata.duration)
1143
- return result
1144
- }
1145
-
1146
- private func formatAirshipData(woosdata: AirshipData) -> [AnyHashable: Any] {
1147
- var result: [AnyHashable: Any] = [:]
1148
- result["name"] = woosdata.eventname
1149
- var propertiesFormat: [AnyHashable: Any] = [:]
1150
- woosdata.properties.keys.forEach { airshipkey in
1151
- if let value = woosdata.properties[airshipkey] as? Date {
1152
- propertiesFormat[airshipkey] = value.timeIntervalSince1970 * 1000
1153
- } else if let value = woosdata.properties[airshipkey] as? Double {
1154
- propertiesFormat[airshipkey] = value
1155
- } else if let value = woosdata.properties[airshipkey] as? Int {
1156
- propertiesFormat[airshipkey] = value
1157
- } else if let value = woosdata.properties[airshipkey] as? Int32 {
1158
- propertiesFormat[airshipkey] = value
1159
- } else if let value = woosdata.properties[airshipkey] as? Bool {
1160
- propertiesFormat[airshipkey] = value
1161
- } else if let value = woosdata.properties[airshipkey] as? String {
1162
- propertiesFormat[airshipkey] = value
1163
- } else {
1164
- propertiesFormat[airshipkey] = woosdata.properties[airshipkey]
1165
- }
1166
- }
1167
- result["properties"] = propertiesFormat
1168
- return result
1169
- }
1170
-
1171
- private func formatMarketingData(woosdata: MarketingData) -> [AnyHashable: Any] {
1172
- var result: [AnyHashable: Any] = [:]
1173
- result["name"] = woosdata.eventname
1174
- var propertiesFormat: [AnyHashable: Any] = [:]
1175
- woosdata.properties.keys.forEach { marketingkey in
1176
- if let value = woosdata.properties[marketingkey] as? Date {
1177
- propertiesFormat[marketingkey] = value.timeIntervalSince1970 * 1000
1178
- } else if let value = woosdata.properties[marketingkey] as? Double {
1179
- propertiesFormat[marketingkey] = value
1180
- } else if let value = woosdata.properties[marketingkey] as? Int {
1181
- propertiesFormat[marketingkey] = value
1182
- } else if let value = woosdata.properties[marketingkey] as? Int32 {
1183
- propertiesFormat[marketingkey] = value
1184
- } else if let value = woosdata.properties[marketingkey] as? Bool {
1185
- propertiesFormat[marketingkey] = value
1186
- } else if let value = woosdata.properties[marketingkey] as? String {
1187
- propertiesFormat[marketingkey] = value
1188
- } else {
1189
- propertiesFormat[marketingkey] = woosdata.properties[marketingkey]
1190
- }
1191
- }
1192
- result["properties"] = propertiesFormat
1193
- return result
1194
- }
1195
- }
1196
-
1197
-
1198
-
1199
- extension PluginGeofencing:CLLocationManagerDelegate{
1200
- func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
1201
- guard let location = locations.last else {
1202
- return
1203
- }
1204
- print(location)
1205
- }
1206
-
1207
- private func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
1208
- print(error)
1209
- }
1210
-
1211
- }
1212
-
1213
- private extension UIApplication {
1214
- /// Returns the top-most view controller in the app
1215
- var topViewController: UIViewController? {
1216
- // 1️⃣ Get key window
1217
- guard let windowScene = connectedScenes
1218
- .first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene,
1219
- let rootVC = windowScene.windows
1220
- .first(where: { $0.isKeyWindow })?.rootViewController
1221
- else {
1222
- return nil
1223
- }
1224
- // 2️⃣ Recursively find top presented VC
1225
- return topViewController(from: rootVC)
1226
- }
1227
-
1228
- private func topViewController(from root: UIViewController) -> UIViewController {
1229
- if let presented = root.presentedViewController {
1230
- // Presented modals
1231
- return topViewController(from: presented)
1232
- } else if let nav = root as? UINavigationController, let visible = nav.visibleViewController {
1233
- // Navigation controller
1234
- return topViewController(from: visible)
1235
- } else if let tab = root as? UITabBarController, let selected = tab.selectedViewController {
1236
- // Tab bar controller
1237
- return topViewController(from: selected)
1238
- } else {
1239
- return root
1240
- }
1241
- }
1242
- }
1243
-