@woosmap/react-native-plugin-geofencing 0.1.2
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/LICENSE +21 -0
- package/README.md +340 -0
- package/android/.gradle/7.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +60 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +365 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingPackage.java +28 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosLocationReadyListener.java +38 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +36 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +34 -0
- package/ios/AirshipEvents.swift +73 -0
- package/ios/DataDistance.swift +61 -0
- package/ios/DataLocation.swift +36 -0
- package/ios/DataPOI.swift +38 -0
- package/ios/DataRegion.swift +78 -0
- package/ios/DataVisit.swift +30 -0
- package/ios/DataZOI.swift +22 -0
- package/ios/MarketingCloudEvents.swift +64 -0
- package/ios/MockDataVisit.swift +167 -0
- package/ios/PluginGeofencing-Bridging-Header.h +3 -0
- package/ios/PluginGeofencing.m +62 -0
- package/ios/PluginGeofencing.swift +688 -0
- package/ios/PluginGeofencing.xcodeproj/project.pbxproj +293 -0
- package/ios/WoosmapGeofenceMessage.swift +40 -0
- package/ios/WoosmapGeofenceService.swift +474 -0
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcuserdata/saturn.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/WoosmapGeofencingPlugin.xcodeproj/xcuserdata/saturn.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/Airship.js +35 -0
- package/lib/commonjs/Airship.js.map +1 -0
- package/lib/commonjs/Location.js +54 -0
- package/lib/commonjs/Location.js.map +1 -0
- package/lib/commonjs/MarketingCloud.js +35 -0
- package/lib/commonjs/MarketingCloud.js.map +1 -0
- package/lib/commonjs/Poi.js +96 -0
- package/lib/commonjs/Poi.js.map +1 -0
- package/lib/commonjs/Region.js +62 -0
- package/lib/commonjs/Region.js.map +1 -0
- package/lib/commonjs/Visit.js +50 -0
- package/lib/commonjs/Visit.js.map +1 -0
- package/lib/commonjs/Zoi.js +97 -0
- package/lib/commonjs/Zoi.js.map +1 -0
- package/lib/commonjs/index.js +276 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/Airship.js +33 -0
- package/lib/module/Airship.js.map +1 -0
- package/lib/module/Location.js +46 -0
- package/lib/module/Location.js.map +1 -0
- package/lib/module/MarketingCloud.js +33 -0
- package/lib/module/MarketingCloud.js.map +1 -0
- package/lib/module/Poi.js +94 -0
- package/lib/module/Poi.js.map +1 -0
- package/lib/module/Region.js +54 -0
- package/lib/module/Region.js.map +1 -0
- package/lib/module/Visit.js +48 -0
- package/lib/module/Visit.js.map +1 -0
- package/lib/module/Zoi.js +95 -0
- package/lib/module/Zoi.js.map +1 -0
- package/lib/module/index.js +261 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/Airship.d.ts +18 -0
- package/lib/typescript/Location.d.ts +26 -0
- package/lib/typescript/MarketingCloud.d.ts +18 -0
- package/lib/typescript/Poi.d.ts +48 -0
- package/lib/typescript/Region.d.ts +30 -0
- package/lib/typescript/Visit.d.ts +25 -0
- package/lib/typescript/Zoi.d.ts +49 -0
- package/lib/typescript/index.d.ts +97 -0
- package/package.json +150 -0
- package/react-native-plugin-geofencing.podspec +20 -0
- package/src/Airship.tsx +24 -0
- package/src/Location.tsx +46 -0
- package/src/MarketingCloud.tsx +24 -0
- package/src/Poi.tsx +106 -0
- package/src/Region.tsx +56 -0
- package/src/Visit.tsx +49 -0
- package/src/Zoi.tsx +107 -0
- package/src/index.tsx +255 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import WoosmapGeofencing
|
|
3
|
+
|
|
4
|
+
@objc(PluginGeofencing)
|
|
5
|
+
class PluginGeofencing: RCTEventEmitter {
|
|
6
|
+
|
|
7
|
+
/// Location routing to check location permission
|
|
8
|
+
private var templocationChecker: CLLocationManager!
|
|
9
|
+
|
|
10
|
+
/// List of location watch collected by plugin
|
|
11
|
+
private var locationWatchStack: [String: String] = [:]
|
|
12
|
+
|
|
13
|
+
/// List of poi watch collected by plugin
|
|
14
|
+
private var poiWatchStack: [String: String] = [:]
|
|
15
|
+
|
|
16
|
+
/// List all callback collect by Search api call
|
|
17
|
+
private var searchAPICallStack: [String: String] = [:]
|
|
18
|
+
|
|
19
|
+
/// List all distance watch collected by plugin
|
|
20
|
+
private var distanceWatchStack: [String: String] = [:]
|
|
21
|
+
|
|
22
|
+
/// List all callback collect by Distance api call
|
|
23
|
+
private var distanceAPICallStack: [String: String] = [:]
|
|
24
|
+
|
|
25
|
+
/// List all region callback collected by plugin
|
|
26
|
+
private var regionWatchStack: [String: String] = [:]
|
|
27
|
+
|
|
28
|
+
/// List all visit callback collected by plugin
|
|
29
|
+
private var visitWatchStack: [String: String] = [:]
|
|
30
|
+
|
|
31
|
+
/// List all airship callback collected by plugin
|
|
32
|
+
private var airshipWatchStack: [String: String] = [:]
|
|
33
|
+
|
|
34
|
+
/// List all marketing callback collected by plugin.
|
|
35
|
+
private var marketingWatchStack: [String: String] = [:]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override func supportedEvents() -> [String]! {
|
|
43
|
+
return ["geolocationDidChange",
|
|
44
|
+
"woosmapgeofenceRegionError",
|
|
45
|
+
"woosmapgeofenceRegionDidChange",
|
|
46
|
+
"woosmapgeofenceRegionError"]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override init() {
|
|
50
|
+
super.init()
|
|
51
|
+
templocationChecker = CLLocationManager()
|
|
52
|
+
templocationChecker.delegate = self
|
|
53
|
+
templocationChecker.desiredAccuracy = kCLLocationAccuracyBest
|
|
54
|
+
locationWatchStack = [:]
|
|
55
|
+
poiWatchStack = [:]
|
|
56
|
+
searchAPICallStack = [:]
|
|
57
|
+
regionWatchStack = [:]
|
|
58
|
+
visitWatchStack = [:]
|
|
59
|
+
distanceWatchStack = [:]
|
|
60
|
+
distanceAPICallStack = [:]
|
|
61
|
+
airshipWatchStack = [:]
|
|
62
|
+
marketingWatchStack = [:]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//MARK: Private method
|
|
66
|
+
private func showWoomapError(_ msg: String) -> NSError {
|
|
67
|
+
var result: [String: Any] = [:]
|
|
68
|
+
result["message"] = msg
|
|
69
|
+
let resultError: NSError = NSError(domain: WoosmapGeofenceMessage.plugin_errorDomain, code: WoosmapGeofenceMessage.plugin_errorcode,userInfo: result)
|
|
70
|
+
return resultError
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc(multiply:withB:withResolver:withRejecter:)
|
|
74
|
+
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
75
|
+
resolve(a*b)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@objc(initialize:withResolver:withRejecter:)
|
|
80
|
+
func initialize(command: NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
|
|
81
|
+
|
|
82
|
+
guard let initparameters = command as? [String: String?] else {
|
|
83
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
84
|
+
WoosmapGeofenceMessage.plugin_parsingFailed,
|
|
85
|
+
showWoomapError(WoosmapGeofenceMessage.plugin_parsingFailed))
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
var isCallUnsuccessfull = false
|
|
89
|
+
var privateKeyWoosmapAPI = ""
|
|
90
|
+
|
|
91
|
+
if let keyWoosmapAPI = initparameters["privateKeyWoosmapAPI"] as? String {
|
|
92
|
+
privateKeyWoosmapAPI = keyWoosmapAPI
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if let trackingProfile = initparameters["trackingProfile"] as? String {
|
|
96
|
+
if ConfigurationProfile(rawValue: trackingProfile) != nil {
|
|
97
|
+
WoosmapGeofenceService.setup(woosmapKey: privateKeyWoosmapAPI, configurationProfile: trackingProfile)
|
|
98
|
+
|
|
99
|
+
} else {
|
|
100
|
+
isCallUnsuccessfull = true
|
|
101
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
102
|
+
WoosmapGeofenceMessage.invalidProfile,
|
|
103
|
+
showWoomapError(WoosmapGeofenceMessage.invalidProfile))
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
} else {
|
|
108
|
+
WoosmapGeofenceService.setup(woosmapKey: privateKeyWoosmapAPI, configurationProfile: "")
|
|
109
|
+
}
|
|
110
|
+
if(isCallUnsuccessfull == false){
|
|
111
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@objc(getPermissionsStatus:withRejecter:)
|
|
117
|
+
func getPermissionsStatus(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
118
|
+
let authorizationStatus: CLAuthorizationStatus
|
|
119
|
+
if #available(iOS 14, *) {
|
|
120
|
+
let manager = CLLocationManager()
|
|
121
|
+
authorizationStatus = manager.authorizationStatus
|
|
122
|
+
} else {
|
|
123
|
+
authorizationStatus = CLLocationManager.authorizationStatus()
|
|
124
|
+
}
|
|
125
|
+
var str: String = "UNKNOWN"
|
|
126
|
+
switch authorizationStatus {
|
|
127
|
+
case .denied:
|
|
128
|
+
str = "DENIED"
|
|
129
|
+
case .restricted:
|
|
130
|
+
str = "DENIED"
|
|
131
|
+
case .authorizedAlways:
|
|
132
|
+
str = "GRANTED_BACKGROUND"
|
|
133
|
+
case .authorizedWhenInUse:
|
|
134
|
+
str = "GRANTED_FOREGROUND"
|
|
135
|
+
default:
|
|
136
|
+
str = "UNKNOWN"
|
|
137
|
+
}
|
|
138
|
+
resolve(str)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Updating new woosmap key
|
|
142
|
+
/// - Parameter command: -
|
|
143
|
+
@objc(setWoosmapApiKey:withResolver:withRejecter:)
|
|
144
|
+
func setWoosmapApiKey(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
|
|
145
|
+
|
|
146
|
+
if let woosmapkey = command[0] as? String {
|
|
147
|
+
if WoosmapGeofenceService.shared != nil {
|
|
148
|
+
do {
|
|
149
|
+
try WoosmapGeofenceService.shared?.setWoosmapAPIKey(key: woosmapkey)
|
|
150
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
151
|
+
} catch let error as WoosGeofenceError {
|
|
152
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
153
|
+
error.localizedDescription,
|
|
154
|
+
showWoomapError(error.localizedDescription))
|
|
155
|
+
} catch {
|
|
156
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
157
|
+
error.localizedDescription,
|
|
158
|
+
showWoomapError(error.localizedDescription))
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
162
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
163
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
167
|
+
WoosmapGeofenceMessage.invalidWoosmapKey,
|
|
168
|
+
showWoomapError(WoosmapGeofenceMessage.invalidWoosmapKey))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@objc(startTracking:withResolver:withRejecter:)
|
|
173
|
+
func startTracking(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void{
|
|
174
|
+
|
|
175
|
+
if let profileName = command[0] as? String {
|
|
176
|
+
if WoosmapGeofenceService.shared != nil {
|
|
177
|
+
do {
|
|
178
|
+
try WoosmapGeofenceService.shared?.startTracking(profile: profileName)
|
|
179
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
180
|
+
} catch let error as WoosGeofenceError {
|
|
181
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
182
|
+
error.localizedDescription,
|
|
183
|
+
showWoomapError(error.localizedDescription))
|
|
184
|
+
} catch {
|
|
185
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
186
|
+
error.localizedDescription,
|
|
187
|
+
showWoomapError(error.localizedDescription))
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
191
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
192
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
196
|
+
WoosmapGeofenceMessage.invalidWoosmapKey,
|
|
197
|
+
showWoomapError(WoosmapGeofenceMessage.invalidWoosmapKey))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// Stop woosgeolocationservice
|
|
202
|
+
/// - Parameter command: -
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/// Stop woosgeolocationservice
|
|
206
|
+
/// - Parameters:
|
|
207
|
+
/// - resolve: return message on sucessfull call
|
|
208
|
+
/// - reject: never called but to manage compatiblity with android promise it is part of plugin
|
|
209
|
+
@objc(stopTracking:withRejecter:)
|
|
210
|
+
func stopTracking (resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
211
|
+
if WoosmapGeofenceService.shared != nil {
|
|
212
|
+
WoosmapGeofenceService.shared?.stopTracking()
|
|
213
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
214
|
+
}
|
|
215
|
+
else{
|
|
216
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
217
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
218
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Showing location permission popup on screen
|
|
223
|
+
/// - Parameters:
|
|
224
|
+
/// - command: background mode true for background access and false for forground access
|
|
225
|
+
/// - resolve: return message on sucessfull call
|
|
226
|
+
/// - reject: return error on function call
|
|
227
|
+
@objc(requestPermissions:withResolver:withRejecter:)
|
|
228
|
+
func requestPermissions(command: NSArray, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock){
|
|
229
|
+
// The requestAlwaysAuthorization will show prompt only for the first time. From then onwards, no prompts are shown.
|
|
230
|
+
// https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization
|
|
231
|
+
|
|
232
|
+
if let backgoundMode = command[0] as? Bool {
|
|
233
|
+
let status = CLLocationManager.authorizationStatus()
|
|
234
|
+
|
|
235
|
+
if backgoundMode {
|
|
236
|
+
if status == .notDetermined {
|
|
237
|
+
self.templocationChecker.requestAlwaysAuthorization()
|
|
238
|
+
} else if status == .authorizedAlways {
|
|
239
|
+
resolve(WoosmapGeofenceMessage.samePermission)
|
|
240
|
+
} else {
|
|
241
|
+
let appname: String = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? ""
|
|
242
|
+
var alertInfo: String = ""
|
|
243
|
+
if status == .denied {
|
|
244
|
+
alertInfo = String(format: WoosmapGeofenceMessage.deniedPermission, appname)
|
|
245
|
+
} else {
|
|
246
|
+
alertInfo = String(format: WoosmapGeofenceMessage.replacePermission, appname)
|
|
247
|
+
}
|
|
248
|
+
let alert = UIAlertController(title: "", message: alertInfo, preferredStyle: UIAlertController.Style.alert)
|
|
249
|
+
alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.cancel, style: UIAlertAction.Style.default, handler: nil))
|
|
250
|
+
alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.setting, style: UIAlertAction.Style.default, handler: { _ in
|
|
251
|
+
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
|
|
252
|
+
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
|
|
253
|
+
}
|
|
254
|
+
}))
|
|
255
|
+
var rootViewController = UIApplication.shared.keyWindow?.rootViewController
|
|
256
|
+
if let navigationController = rootViewController as? UINavigationController {
|
|
257
|
+
rootViewController = navigationController.viewControllers.first
|
|
258
|
+
}
|
|
259
|
+
if let tabBarController = rootViewController as? UITabBarController {
|
|
260
|
+
rootViewController = tabBarController.selectedViewController
|
|
261
|
+
}
|
|
262
|
+
rootViewController?.present(alert, animated: true, completion: nil)
|
|
263
|
+
resolve(WoosmapGeofenceMessage.showingPermissionBox)
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
if status == .notDetermined {
|
|
267
|
+
self.templocationChecker.requestWhenInUseAuthorization()
|
|
268
|
+
} else if status == .authorizedWhenInUse {
|
|
269
|
+
resolve(WoosmapGeofenceMessage.samePermission)
|
|
270
|
+
} else {
|
|
271
|
+
resolve(WoosmapGeofenceMessage.showingPermissionBox)
|
|
272
|
+
DispatchQueue.main.async {
|
|
273
|
+
let appname: String = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? ""
|
|
274
|
+
var alertInfo: String = ""
|
|
275
|
+
if status == .denied {
|
|
276
|
+
alertInfo = String(format: WoosmapGeofenceMessage.deniedPermission, appname)
|
|
277
|
+
} else {
|
|
278
|
+
alertInfo = String(format: WoosmapGeofenceMessage.replacePermission, appname)
|
|
279
|
+
}
|
|
280
|
+
let alert = UIAlertController(title: "", message: alertInfo, preferredStyle: UIAlertController.Style.alert)
|
|
281
|
+
alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.cancel, style: UIAlertAction.Style.default, handler: nil))
|
|
282
|
+
alert.addAction(UIAlertAction(title: WoosmapGeofenceMessage.setting, style: UIAlertAction.Style.default, handler: { _ in
|
|
283
|
+
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
|
|
284
|
+
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
|
|
285
|
+
}
|
|
286
|
+
}))
|
|
287
|
+
var rootViewController = UIApplication.shared.keyWindow?.rootViewController
|
|
288
|
+
if let navigationController = rootViewController as? UINavigationController {
|
|
289
|
+
rootViewController = navigationController.viewControllers.first
|
|
290
|
+
}
|
|
291
|
+
if let tabBarController = rootViewController as? UITabBarController {
|
|
292
|
+
rootViewController = tabBarController.selectedViewController
|
|
293
|
+
}
|
|
294
|
+
rootViewController?.present(alert, animated: true, completion: nil)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
/// Adding Location watch
|
|
307
|
+
/// - Parameters:
|
|
308
|
+
/// - watchid: Reference Watch ID
|
|
309
|
+
/// - resolve: return reference watchid on successfully call
|
|
310
|
+
/// - reject: return error info
|
|
311
|
+
@objc(watchLocation:withResolver:withRejecter:)
|
|
312
|
+
func watchLocation(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
313
|
+
if WoosmapGeofenceService.shared != nil {
|
|
314
|
+
locationWatchStack[watchid] = watchid
|
|
315
|
+
if locationWatchStack.count == 1 {
|
|
316
|
+
NotificationCenter.default.addObserver(
|
|
317
|
+
self,
|
|
318
|
+
selector: #selector(newLocationAdded(_:)),
|
|
319
|
+
name: .newLocationSaved,
|
|
320
|
+
object: nil)
|
|
321
|
+
}
|
|
322
|
+
resolve(watchid)
|
|
323
|
+
} else {
|
|
324
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
325
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
326
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
/// Clear location watch for given id
|
|
333
|
+
/// - Parameters:
|
|
334
|
+
/// - watchid: Reference to clear watch
|
|
335
|
+
/// - resolve: return Reference watchid on successfully call
|
|
336
|
+
/// - reject: return error info
|
|
337
|
+
@objc(clearLocationWatch:withResolver:withRejecter:)
|
|
338
|
+
func clearLocationWatch(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
339
|
+
|
|
340
|
+
if let _ = locationWatchStack[watchid] {
|
|
341
|
+
locationWatchStack.removeValue(forKey: watchid)
|
|
342
|
+
}
|
|
343
|
+
if locationWatchStack.count == 0 {
|
|
344
|
+
// remove delegate watch
|
|
345
|
+
NotificationCenter.default.removeObserver(self, name: .newLocationSaved, object: nil)
|
|
346
|
+
}
|
|
347
|
+
resolve(watchid)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/// Clear all location callback
|
|
351
|
+
/// - Parameters:
|
|
352
|
+
/// - resolve: return Reference watchid on successfully call
|
|
353
|
+
/// - reject: return error info
|
|
354
|
+
@objc(clearAllLocationWatch:withRejecter:)
|
|
355
|
+
func clearAllLocationWatch(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
356
|
+
locationWatchStack.removeAll()
|
|
357
|
+
if locationWatchStack.count == 0 {
|
|
358
|
+
// remove delegate watch
|
|
359
|
+
NotificationCenter.default.removeObserver(self, name: .newLocationSaved, object: nil)
|
|
360
|
+
}
|
|
361
|
+
resolve("00000-00000-0000")
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
/// Adding Region watch
|
|
366
|
+
/// - Parameters:
|
|
367
|
+
/// - watchid: Reference Watch ID
|
|
368
|
+
/// - resolve: return reference watchid on successfully call
|
|
369
|
+
/// - reject: return error info
|
|
370
|
+
@objc(watchRegions:withResolver:withRejecter:)
|
|
371
|
+
func watchRegions(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
372
|
+
if WoosmapGeofenceService.shared != nil {
|
|
373
|
+
regionWatchStack[watchid] = watchid
|
|
374
|
+
if regionWatchStack.count == 1 {
|
|
375
|
+
NotificationCenter.default.addObserver(
|
|
376
|
+
self,
|
|
377
|
+
selector: #selector(didEventPOIRegion(_:)),
|
|
378
|
+
name: .didEventPOIRegion,
|
|
379
|
+
object: nil)
|
|
380
|
+
}
|
|
381
|
+
resolve(watchid)
|
|
382
|
+
} else {
|
|
383
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
384
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
385
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/// Clear Region watch for given id
|
|
391
|
+
/// - Parameters:
|
|
392
|
+
/// - watchid: Reference to clear watch
|
|
393
|
+
/// - resolve: return Reference watchid on successfully call
|
|
394
|
+
/// - reject: return error info
|
|
395
|
+
@objc(clearRegionsWatch:withResolver:withRejecter:)
|
|
396
|
+
func clearRegionsWatch(watchid: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
397
|
+
|
|
398
|
+
if let _ = regionWatchStack[watchid] {
|
|
399
|
+
regionWatchStack.removeValue(forKey: watchid)
|
|
400
|
+
}
|
|
401
|
+
if regionWatchStack.count == 0 {
|
|
402
|
+
// remove delegate watch
|
|
403
|
+
NotificationCenter.default.removeObserver(self, name: .didEventPOIRegion, object: nil)
|
|
404
|
+
}
|
|
405
|
+
resolve(watchid)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/// Clear all region callback
|
|
409
|
+
/// - Parameters:
|
|
410
|
+
/// - resolve: return Reference watchid on successfully call
|
|
411
|
+
/// - reject: return error info
|
|
412
|
+
@objc(clearAllRegionsWatch:withRejecter:)
|
|
413
|
+
func clearAllRegionsWatch(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
414
|
+
regionWatchStack.removeAll()
|
|
415
|
+
if regionWatchStack.count == 0 {
|
|
416
|
+
// remove delegate watch
|
|
417
|
+
NotificationCenter.default.removeObserver(self, name: .didEventPOIRegion, object: nil)
|
|
418
|
+
}
|
|
419
|
+
resolve("00000-00000-0000")
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/// Added SFMC Credentials to SDK
|
|
423
|
+
/// - Parameters:
|
|
424
|
+
/// - credentials: SFMC Credentials object
|
|
425
|
+
/// - resolve: return Reference watchid on successfully call
|
|
426
|
+
/// - reject: return error info
|
|
427
|
+
@objc(setSFMCCredentials:withResolver:withRejecter:)
|
|
428
|
+
func setSFMCCredentials (credentials: NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
429
|
+
if WoosmapGeofenceService.shared != nil {
|
|
430
|
+
if let credentials = credentials as? [String: String] {
|
|
431
|
+
do {
|
|
432
|
+
try WoosmapGeofenceService.shared?.setSFMCCredentials(credentials: credentials)
|
|
433
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
434
|
+
} catch let error as WoosGeofenceError {
|
|
435
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
436
|
+
error.localizedDescription,
|
|
437
|
+
showWoomapError(error.localizedDescription))
|
|
438
|
+
} catch {
|
|
439
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
440
|
+
error.localizedDescription,
|
|
441
|
+
showWoomapError(error.localizedDescription))
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
445
|
+
WoosmapGeofenceMessage.invalidSFMCCredentials,
|
|
446
|
+
showWoomapError(WoosmapGeofenceMessage.invalidSFMCCredentials))
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
450
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
451
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/// 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").
|
|
456
|
+
/// - Parameters:
|
|
457
|
+
/// - radius: radius enum or number in meters
|
|
458
|
+
/// - resolve: return Ok on successfully call
|
|
459
|
+
/// - reject: return error info
|
|
460
|
+
@objc(setPoiRadius:withResolver:withRejecter:)
|
|
461
|
+
func setPoiRadius (radius: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
|
|
462
|
+
if WoosmapGeofenceService.shared != nil {
|
|
463
|
+
var userInputRadiusValue: String = ""
|
|
464
|
+
if let radius = Int32(radius) {
|
|
465
|
+
userInputRadiusValue = String(radius)
|
|
466
|
+
}
|
|
467
|
+
else if let radius = Double(radius) {
|
|
468
|
+
userInputRadiusValue = String(radius)
|
|
469
|
+
}
|
|
470
|
+
else{
|
|
471
|
+
userInputRadiusValue = radius
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if(userInputRadiusValue != ""){
|
|
475
|
+
WoosmapGeofenceService.shared?.setPoiRadius(radius: userInputRadiusValue)
|
|
476
|
+
resolve(WoosmapGeofenceMessage.initialize)
|
|
477
|
+
|
|
478
|
+
} else {
|
|
479
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
480
|
+
WoosmapGeofenceMessage.invalidPOIRadius,
|
|
481
|
+
showWoomapError(WoosmapGeofenceMessage.invalidPOIRadius))
|
|
482
|
+
}
|
|
483
|
+
} else {
|
|
484
|
+
reject(WoosmapGeofenceMessage.plugin_errorDomain,
|
|
485
|
+
WoosmapGeofenceMessage.woosemapNotInitialized,
|
|
486
|
+
showWoomapError(WoosmapGeofenceMessage.woosemapNotInitialized))
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
// MARK: Events
|
|
492
|
+
@objc func newLocationAdded(_ notification: Notification) {
|
|
493
|
+
if let location = notification.userInfo?["Location"] as? Location {
|
|
494
|
+
if(locationWatchStack.count>0){
|
|
495
|
+
sendEvent(withName: "geolocationDidChange", body: formatLocationData(woosdata:location))
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
@objc func didEventPOIRegion(_ notification: Notification) {
|
|
501
|
+
if let region = notification.userInfo?["Region"] as? Region {
|
|
502
|
+
sendEvent(withName: "woosmapgeofenceRegionDidChange", body: formatRegionData(woosdata:region))
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// MARK: Supporting functions
|
|
507
|
+
private func formatLocationData(woosdata: Location) -> [AnyHashable: Any] {
|
|
508
|
+
var result: [AnyHashable: Any] = [:]
|
|
509
|
+
if let date = woosdata.date {
|
|
510
|
+
result["date"] = date.timeIntervalSince1970 * 1000
|
|
511
|
+
} else {
|
|
512
|
+
result["date"] = 0
|
|
513
|
+
}
|
|
514
|
+
result["latitude"] = woosdata.latitude
|
|
515
|
+
result["locationdescription"] = woosdata.locationDescription
|
|
516
|
+
result["locationid"] = woosdata.locationId
|
|
517
|
+
result["longitude"] = woosdata.longitude
|
|
518
|
+
return result
|
|
519
|
+
}
|
|
520
|
+
private func formatPOIData(woosdata: POI) -> [AnyHashable: Any] {
|
|
521
|
+
var result: [AnyHashable: Any] = [:]
|
|
522
|
+
if let data = woosdata.jsonData {
|
|
523
|
+
do {
|
|
524
|
+
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
|
|
525
|
+
result["jsondata"] = json
|
|
526
|
+
} catch { print("Invalid JSON format") }
|
|
527
|
+
}
|
|
528
|
+
result["city"] = woosdata.city
|
|
529
|
+
result["idstore"] = woosdata.idstore
|
|
530
|
+
result["name"] = woosdata.name
|
|
531
|
+
if let date = woosdata.date {
|
|
532
|
+
result["date"] = date.timeIntervalSince1970 * 1000
|
|
533
|
+
} else {
|
|
534
|
+
result["date"] = 0
|
|
535
|
+
}
|
|
536
|
+
result["distance"] = woosdata.distance
|
|
537
|
+
result["duration"] = woosdata.duration ?? "-"
|
|
538
|
+
result["latitude"] = woosdata.latitude
|
|
539
|
+
result["locationid"] = woosdata.locationId
|
|
540
|
+
result["longitude"] = woosdata.longitude
|
|
541
|
+
result["zipcode"] = woosdata.zipCode
|
|
542
|
+
result["radius"] = woosdata.radius
|
|
543
|
+
result["address"] = woosdata.address
|
|
544
|
+
result["countrycode"] = woosdata.countryCode
|
|
545
|
+
result["tags"] = woosdata.tags
|
|
546
|
+
result["types"] = woosdata.types
|
|
547
|
+
result["contact"] = woosdata.contact
|
|
548
|
+
return result
|
|
549
|
+
}
|
|
550
|
+
private func formatZOIData(woosdata: ZOI) -> [AnyHashable: Any] {
|
|
551
|
+
var result: [AnyHashable: Any] = [:]
|
|
552
|
+
result["accumulator"] = woosdata.accumulator
|
|
553
|
+
result["age"] = woosdata.age
|
|
554
|
+
result["covariance_det"] = woosdata.covariance_det
|
|
555
|
+
result["duration"] = woosdata.duration
|
|
556
|
+
if let date = woosdata.endTime {
|
|
557
|
+
result["endtime"] = date.timeIntervalSince1970 * 1000
|
|
558
|
+
} else {
|
|
559
|
+
result["endtime"] = 0
|
|
560
|
+
}
|
|
561
|
+
result["idvisits"] = woosdata.idVisits
|
|
562
|
+
result["latmean"] = woosdata.latMean
|
|
563
|
+
result["lngmean"] = woosdata.lngMean
|
|
564
|
+
result["period"] = woosdata.period
|
|
565
|
+
result["prior_probability"] = woosdata.prior_probability
|
|
566
|
+
result["starttime"] = woosdata.startTime
|
|
567
|
+
result["weekly_density"] = woosdata.weekly_density
|
|
568
|
+
result["wktpolygon"] = woosdata.wktPolygon
|
|
569
|
+
result["x00covariance_matrix_inverse"] = woosdata.x00Covariance_matrix_inverse
|
|
570
|
+
result["x01covariance_matrix_inverse"] = woosdata.x01Covariance_matrix_inverse
|
|
571
|
+
result["x10covariance_matrix_inverse"] = woosdata.x10Covariance_matrix_inverse
|
|
572
|
+
result["x11covariance_matrix_inverse"] = woosdata.x11Covariance_matrix_inverse
|
|
573
|
+
return result
|
|
574
|
+
}
|
|
575
|
+
private func formatVisitData(woosdata: Visit) -> [AnyHashable: Any] {
|
|
576
|
+
var result: [AnyHashable: Any] = [:]
|
|
577
|
+
result["accuracy"] = woosdata.accuracy
|
|
578
|
+
if let date = woosdata.date {
|
|
579
|
+
result["date"] = date.timeIntervalSince1970 * 1000
|
|
580
|
+
} else {
|
|
581
|
+
result["date"] = 0
|
|
582
|
+
}
|
|
583
|
+
if let date = woosdata.arrivalDate {
|
|
584
|
+
result["arrivaldate"] = date.timeIntervalSince1970 * 1000
|
|
585
|
+
} else {
|
|
586
|
+
result["arrivaldate"] = 0
|
|
587
|
+
}
|
|
588
|
+
if let date = woosdata.departureDate {
|
|
589
|
+
result["departuredate"] = date.timeIntervalSince1970 * 1000
|
|
590
|
+
} else {
|
|
591
|
+
result["departuredate"] = 0
|
|
592
|
+
}
|
|
593
|
+
result["latitude"] = woosdata.latitude
|
|
594
|
+
result["longitude"] = woosdata.longitude
|
|
595
|
+
return result
|
|
596
|
+
}
|
|
597
|
+
private func formatRegionData(woosdata: Region) -> [AnyHashable: Any] {
|
|
598
|
+
var result: [AnyHashable: Any] = [:]
|
|
599
|
+
result["date"] = woosdata.date.timeIntervalSince1970 * 1000
|
|
600
|
+
// if let date = woosdata.date {
|
|
601
|
+
// result["date"] = date.timeIntervalSince1970 * 1000
|
|
602
|
+
// } else {
|
|
603
|
+
// result["date"] = 0
|
|
604
|
+
// }
|
|
605
|
+
result["didenter"] = woosdata.didEnter
|
|
606
|
+
result["identifier"] = woosdata.identifier
|
|
607
|
+
result["latitude"] = woosdata.latitude
|
|
608
|
+
result["longitude"] = woosdata.longitude
|
|
609
|
+
result["radius"] = woosdata.radius
|
|
610
|
+
result["frompositiondetection"] = woosdata.fromPositionDetection
|
|
611
|
+
return result
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private func formatDistanceData(woosdata: DistanceResponseResult) -> [AnyHashable: Any] {
|
|
615
|
+
var result: [AnyHashable: Any] = [:]
|
|
616
|
+
result["locationid"] = woosdata.locationId
|
|
617
|
+
//TODO: format it
|
|
618
|
+
result["distance"] = "" //woosdata.distance.text
|
|
619
|
+
result["duration"] = "" //woosdata.duration.text
|
|
620
|
+
return result
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
private func formatAirshipData(woosdata: AirshipData) -> [AnyHashable: Any] {
|
|
624
|
+
var result: [AnyHashable: Any] = [:]
|
|
625
|
+
result["name"] = woosdata.eventname
|
|
626
|
+
var propertiesFormat: [AnyHashable: Any] = [:]
|
|
627
|
+
woosdata.properties.keys.forEach { airshipkey in
|
|
628
|
+
if let value = woosdata.properties[airshipkey] as? Date {
|
|
629
|
+
propertiesFormat[airshipkey] = value.timeIntervalSince1970 * 1000
|
|
630
|
+
} else if let value = woosdata.properties[airshipkey] as? Double {
|
|
631
|
+
propertiesFormat[airshipkey] = value
|
|
632
|
+
} else if let value = woosdata.properties[airshipkey] as? Int {
|
|
633
|
+
propertiesFormat[airshipkey] = value
|
|
634
|
+
} else if let value = woosdata.properties[airshipkey] as? Int32 {
|
|
635
|
+
propertiesFormat[airshipkey] = value
|
|
636
|
+
} else if let value = woosdata.properties[airshipkey] as? Bool {
|
|
637
|
+
propertiesFormat[airshipkey] = value
|
|
638
|
+
} else if let value = woosdata.properties[airshipkey] as? String {
|
|
639
|
+
propertiesFormat[airshipkey] = value
|
|
640
|
+
} else {
|
|
641
|
+
propertiesFormat[airshipkey] = woosdata.properties[airshipkey]
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
result["properties"] = propertiesFormat
|
|
645
|
+
return result
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
private func formatMarketingData(woosdata: MarketingData) -> [AnyHashable: Any] {
|
|
649
|
+
var result: [AnyHashable: Any] = [:]
|
|
650
|
+
result["name"] = woosdata.eventname
|
|
651
|
+
var propertiesFormat: [AnyHashable: Any] = [:]
|
|
652
|
+
woosdata.properties.keys.forEach { marketingkey in
|
|
653
|
+
if let value = woosdata.properties[marketingkey] as? Date {
|
|
654
|
+
propertiesFormat[marketingkey] = value.timeIntervalSince1970 * 1000
|
|
655
|
+
} else if let value = woosdata.properties[marketingkey] as? Double {
|
|
656
|
+
propertiesFormat[marketingkey] = value
|
|
657
|
+
} else if let value = woosdata.properties[marketingkey] as? Int {
|
|
658
|
+
propertiesFormat[marketingkey] = value
|
|
659
|
+
} else if let value = woosdata.properties[marketingkey] as? Int32 {
|
|
660
|
+
propertiesFormat[marketingkey] = value
|
|
661
|
+
} else if let value = woosdata.properties[marketingkey] as? Bool {
|
|
662
|
+
propertiesFormat[marketingkey] = value
|
|
663
|
+
} else if let value = woosdata.properties[marketingkey] as? String {
|
|
664
|
+
propertiesFormat[marketingkey] = value
|
|
665
|
+
} else {
|
|
666
|
+
propertiesFormat[marketingkey] = woosdata.properties[marketingkey]
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
result["properties"] = propertiesFormat
|
|
670
|
+
return result
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
extension PluginGeofencing:CLLocationManagerDelegate{
|
|
677
|
+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
|
678
|
+
guard let location = locations.last else {
|
|
679
|
+
return
|
|
680
|
+
}
|
|
681
|
+
print(location)
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
|
|
685
|
+
print(error)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
}
|