From e5c0bcb7f3a37311fb1ca7f0b556f050fb04d4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Leroy?= Date: Thu, 17 Sep 2020 11:04:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=8F=20fix=20[value]=20placeholder=20is?= =?UTF-8?q?=20notifs'=20message=20not=20replaced=20after=20app=20has=20bee?= =?UTF-8?q?n=20killed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/RNSimpleNativeGeofencing.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ios/RNSimpleNativeGeofencing.swift b/ios/RNSimpleNativeGeofencing.swift index 91bd274..29a1489 100644 --- a/ios/RNSimpleNativeGeofencing.swift +++ b/ios/RNSimpleNativeGeofencing.swift @@ -17,7 +17,6 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs //MARK: - Init / Setup / Vars - static let sharedInstance = RNSimpleNativeGeofencing() let locationManager = CLLocationManager() @@ -43,7 +42,6 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs var globalDeletionTimer = 0 var globaltimer: Timer? - var valueDic: Dictionary = [:] var locationAuthorized = true var notificationAuthorized = true @@ -138,7 +136,7 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs ) if value != nil { - self.valueDic[id] = value! + UserDefaults.standard.set(value, forKey: id); } geofenceRegion.notifyOnExit = true @@ -284,7 +282,7 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs for geo in self.currentActiveGeofences { - self.valueDic[geo.identifier] = nil + UserDefaults.standard.removeObject(forKey: geo.identifier) self.locationManager.stopMonitoring(for: geo) @@ -313,7 +311,7 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs for geo in self.currentActiveGeofences { if geo.identifier == geofenceKey{ - self.valueDic[geo.identifier] = nil + UserDefaults.standard.removeObject(forKey: geo.identifier) self.locationManager.stopMonitoring(for: geo) self.currentActiveGeofences.remove(at: count) @@ -325,7 +323,7 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs for geo in self.currentGeofences { if geo.identifier == geofenceKey{ - self.valueDic[geo.identifier] = nil + UserDefaults.standard.removeObject(forKey: geo.identifier) self.currentGeofences.remove(at: count2) } @@ -422,7 +420,6 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs //MARK: - Setup Notifications private func handleEvent(region: CLRegion!, didEnter: Bool) { - if region.identifier == "monitor" { if didEnter { @@ -452,13 +449,13 @@ class RNSimpleNativeGeofencing: RCTEventEmitter, CLLocationManagerDelegate, UNUs if self.didEnterBody.contains("[value]") { - if let value = self.valueDic[region.identifier] { + if let value = UserDefaults.standard.string(forKey: region.identifier) { self.didEnterBody = self.didEnterBody.replacingOccurrences(of: "[value]", with: value, options: NSString.CompareOptions.literal, range:nil) } } if self.didExitBody.contains("[value]") { - if let value = self.valueDic[region.identifier] { + if let value = UserDefaults.standard.string(forKey: region.identifier) { self.didExitBody = self.didExitBody.replacingOccurrences(of: "[value]", with: value, options: NSString.CompareOptions.literal, range:nil) } }