spotny-sdk 1.0.37 → 1.0.40
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.
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
<!-- Location is required for beacon scanning on API < 31 -->
|
|
11
11
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
12
|
-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
13
12
|
<!-- Background location required for background scanning -->
|
|
14
13
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
15
14
|
|
|
@@ -4,7 +4,7 @@ import android.app.NotificationChannel
|
|
|
4
4
|
import android.app.NotificationManager
|
|
5
5
|
import android.content.Context
|
|
6
6
|
import android.os.Build
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import android.util.Log
|
|
9
9
|
import androidx.core.app.NotificationCompat
|
|
10
10
|
import com.facebook.react.bridge.*
|
|
@@ -113,12 +113,15 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
113
113
|
BeaconManager.setDebug(false)
|
|
114
114
|
beaconManager.setEnableScheduledScanJobs(false)
|
|
115
115
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
116
|
-
val channelId = "spotny_sdk_channel"
|
|
117
116
|
val notifManager = reactContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
notifManager.createNotificationChannel(
|
|
118
|
+
NotificationChannel("spotny_sdk_service", "Spotny Scanning", NotificationManager.IMPORTANCE_LOW)
|
|
119
|
+
)
|
|
120
|
+
notifManager.createNotificationChannel(
|
|
121
|
+
NotificationChannel("spotny_sdk_alerts", "Spotny Beacon Alerts", NotificationManager.IMPORTANCE_DEFAULT)
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
val notification = NotificationCompat.Builder(reactContext, "spotny_sdk_service")
|
|
122
125
|
.setSmallIcon(reactContext.applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_dialog_info)
|
|
123
126
|
.setContentTitle("Spotny")
|
|
124
127
|
.setContentText("Scanning for nearby beacons…")
|
|
@@ -163,13 +166,11 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
override fun stopScanner(promise: Promise) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
beaconManager.stopMonitoringBeaconsInRegion(region)
|
|
172
|
-
} catch (_: RemoteException) {}
|
|
169
|
+
beaconManager.removeAllMonitorNotifiers()
|
|
170
|
+
beaconManager.removeAllRangeNotifiers()
|
|
171
|
+
val region = Region("SpotnySDK_General", Identifier.parse(BEACON_UUID), null, null)
|
|
172
|
+
beaconManager.stopRangingBeacons(region)
|
|
173
|
+
beaconManager.stopMonitoring(region)
|
|
173
174
|
|
|
174
175
|
cleanupAllState()
|
|
175
176
|
|
|
@@ -270,6 +271,9 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
override fun clearDebounceCache(promise: Promise) {
|
|
274
|
+
lastProximityEventSent.clear()
|
|
275
|
+
lastImpressionEventSent.clear()
|
|
276
|
+
lastProximityDistance.clear()
|
|
273
277
|
promise.resolve("Debounce cache cleared")
|
|
274
278
|
}
|
|
275
279
|
|
|
@@ -297,8 +301,8 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
297
301
|
beaconManager.addRangeNotifier(rangeNotifier)
|
|
298
302
|
beaconManager.addMonitorNotifier(monitorNotifier)
|
|
299
303
|
|
|
300
|
-
beaconManager.
|
|
301
|
-
beaconManager.
|
|
304
|
+
beaconManager.startRangingBeacons(region)
|
|
305
|
+
beaconManager.startMonitoring(region)
|
|
302
306
|
|
|
303
307
|
Log.d(TAG, "Scanning for UUID $BEACON_UUID")
|
|
304
308
|
}
|
|
@@ -437,7 +441,8 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
437
441
|
putString("event", "enter")
|
|
438
442
|
}
|
|
439
443
|
sendEvent("onBeaconRegionEvent", payload)
|
|
440
|
-
|
|
444
|
+
sendLocalNotification("📍 Beacon Region Entered", region.uniqueId)
|
|
445
|
+
beaconManager.startRangingBeacons(region)
|
|
441
446
|
}
|
|
442
447
|
|
|
443
448
|
override fun didExitRegion(region: Region) {
|
|
@@ -447,9 +452,10 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
447
452
|
putString("event", "exit")
|
|
448
453
|
}
|
|
449
454
|
sendEvent("onBeaconRegionEvent", payload)
|
|
455
|
+
sendLocalNotification("🚪 Beacon Region Exited", region.uniqueId)
|
|
450
456
|
// FIX #3: delegate to cleanupAllState which now uses lastProximityEventSent
|
|
451
457
|
cleanupAllState()
|
|
452
|
-
|
|
458
|
+
beaconManager.stopRangingBeacons(region)
|
|
453
459
|
}
|
|
454
460
|
|
|
455
461
|
override fun didDetermineStateForRegion(state: Int, region: Region) {
|
|
@@ -493,21 +499,16 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
|
|
|
493
499
|
}
|
|
494
500
|
|
|
495
501
|
private fun sendLocalNotification(title: String, body: String) {
|
|
496
|
-
val channelId = "spotny_sdk_channel"
|
|
497
502
|
val notifManager = reactContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
498
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
499
|
-
val channel = NotificationChannel(channelId, "Spotny SDK", NotificationManager.IMPORTANCE_DEFAULT)
|
|
500
|
-
notifManager.createNotificationChannel(channel)
|
|
501
|
-
}
|
|
502
503
|
val appIcon = reactContext.applicationInfo.icon.takeIf { it != 0 }
|
|
503
504
|
?: android.R.drawable.ic_dialog_info
|
|
504
|
-
val notification = NotificationCompat.Builder(reactContext,
|
|
505
|
+
val notification = NotificationCompat.Builder(reactContext, "spotny_sdk_alerts")
|
|
505
506
|
.setSmallIcon(appIcon)
|
|
506
507
|
.setContentTitle(title)
|
|
507
508
|
.setContentText(body)
|
|
508
509
|
.setAutoCancel(true)
|
|
509
510
|
.build()
|
|
510
|
-
notifManager.notify(System.currentTimeMillis().toInt(), notification)
|
|
511
|
+
notifManager.notify((System.currentTimeMillis() % Int.MAX_VALUE).toInt(), notification)
|
|
511
512
|
}
|
|
512
513
|
|
|
513
514
|
private fun logFile() = File(reactContext.filesDir, "spotny_beacon_debug.log")
|
|
@@ -339,6 +339,9 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
339
339
|
withResolve resolve: @escaping (Any?) -> Void,
|
|
340
340
|
reject: @escaping (String?, String?, Error?) -> Void
|
|
341
341
|
) {
|
|
342
|
+
lastProximityEventSent.removeAll()
|
|
343
|
+
lastImpressionEventSent.removeAll()
|
|
344
|
+
lastProximityDistance.removeAll()
|
|
342
345
|
resolve("Debounce cache cleared")
|
|
343
346
|
}
|
|
344
347
|
|