Skip to content

Commit

Permalink
Feature flagged removal of beacon monitoring (#300)
Browse files Browse the repository at this point in the history
* Update RadarLocationManager.m

* send empty beacons array instead of nil

* gate using feature flag

* change flag name

* Update RadarLocationManager.m

* Revert "Update RadarLocationManager.m"

This reverts commit 40e918ce02d14163fc0598e23cddcde5bacbe64b.

* bump to 3.9.6

* Update project.pbxproj

* use feature gate here

* bump

* Update RadarBeaconManager.m

* Bump to 3.10.2

* 3.11.0

---------

Co-authored-by: KennyHuRadar <[email protected]>
Co-authored-by: Liam Meier <[email protected]>
  • Loading branch information
3 people authored May 24, 2024
1 parent 3b716bf commit 61758ab
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 42 deletions.
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.10.1'
s.version = '3.11.0'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
4 changes: 2 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.10.1;
MARKETING_VERSION = 3.11.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1051,7 +1051,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.10.1;
MARKETING_VERSION = 3.11.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
26 changes: 24 additions & 2 deletions RadarSDK/RadarBeaconManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,19 @@ - (CLBeaconRegion *)regionForUUID:(NSString *)uuid {
}

- (void)handleBeacons {
if (self.beaconUUIDs.count == 0 && self.nearbyBeaconIdentifiers.count + self.failedBeaconIdentifiers.count == self.beacons.count) {
if ((self.beaconUUIDs.count == 0 || [RadarSettings useRadarModifiedBeacon]) &&
self.nearbyBeaconIdentifiers.count + self.failedBeaconIdentifiers.count == self.beacons.count) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Finished ranging"]];

[self stopRanging];
}
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Failed to monitor beacon | region.identifier = %@", region.identifier]];

[self.failedBeaconIdentifiers addObject:region.identifier];
Expand All @@ -294,8 +299,9 @@ - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(nonnull NS
[self.nearbyBeacons addObject:[RadarBeacon fromCLBeacon:beacon]];

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug
message:[NSString stringWithFormat:@"Ranged beacon | nearbyBeacons.count = %lu; region.identifier = %@; beacon.uuid = %@; beacon.major "
message:[NSString stringWithFormat:@"Ranged beacon with RSSI %ld | nearbyBeacons.count = %lu; region.identifier = %@; beacon.uuid = %@; beacon.major "
@"= %@; beacon.minor = %@; beacon.rssi = %ld; beacon.proximity = %ld",
(unsigned long)beacon.rssi,
(unsigned long)self.nearbyBeacons.count, region.identifier, [beacon.proximityUUID UUIDString],
beacon.major, beacon.minor, (unsigned long)beacon.rssi, (unsigned long)beacon.proximity]];
}
Expand All @@ -304,6 +310,10 @@ - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(nonnull NS
}

- (void)handleBeaconEntryForRegion:(CLBeaconRegion *)region completionHandler:(RadarBeaconCompletionHandler)completionHandler {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

NSString *identifier = region.identifier;
BOOL alreadyInside = [self.nearbyBeaconIdentifiers containsObject:identifier];
if (alreadyInside) {
Expand All @@ -319,6 +329,10 @@ - (void)handleBeaconEntryForRegion:(CLBeaconRegion *)region completionHandler:(R
}

- (void)handleBeaconExitForRegion:(CLBeaconRegion *)region completionHandler:(RadarBeaconCompletionHandler)completionHandler {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

NSString *identifier = region.identifier;
BOOL alreadyOutside = ![self.nearbyBeaconIdentifiers containsObject:identifier];
if (alreadyOutside) {
Expand All @@ -334,11 +348,19 @@ - (void)handleBeaconExitForRegion:(CLBeaconRegion *)region completionHandler:(Ra
}

- (void)handleBeaconUUIDEntryForRegion:(CLBeaconRegion *)region completionHandler:(RadarBeaconCompletionHandler)completionHandler {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

NSArray<NSString *> *beaconUUIDs = [RadarSettings beaconUUIDs];
[self rangeBeaconUUIDs:beaconUUIDs completionHandler:completionHandler];
}

- (void)handleBeaconUUIDExitForRegion:(CLBeaconRegion *)region completionHandler:(RadarBeaconCompletionHandler)completionHandler {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

NSArray<NSString *> *beaconUUIDs = [RadarSettings beaconUUIDs];
[self rangeBeaconUUIDs:beaconUUIDs completionHandler:completionHandler];
}
Expand Down
4 changes: 3 additions & 1 deletion RadarSDK/RadarFeatureSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL usePersistence;
@property (nonatomic, assign) BOOL extendFlushReplays;
@property (nonatomic, assign) BOOL useLogPersistence;
@property (nonatomic, assign) BOOL useRadarModifiedBeacon;

/**
Initializes a new RadarFeatureSettings object with given value.
Expand All @@ -30,7 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithUsePersistence:(BOOL)usePersistence
extendFlushReplays:(BOOL)extendFlushReplays
useLogPersistence:(BOOL)useLogPersistence;
useLogPersistence:(BOOL)useLogPersistence
useRadarModifiedBeacon:(BOOL)useRadarModifiedBeacon;

/**
Creates a RadarFeatureSettings object from the provided dictionary.
Expand Down
21 changes: 18 additions & 3 deletions RadarSDK/RadarFeatureSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ @implementation RadarFeatureSettings

- (instancetype)initWithUsePersistence:(BOOL)usePersistence
extendFlushReplays:(BOOL)extendFlushReplays
useLogPersistence:(BOOL)useLogPersistence {
useLogPersistence:(BOOL)useLogPersistence
useRadarModifiedBeacon:(BOOL)useRadarModifiedBeacon{
if (self = [super init]) {
_usePersistence = usePersistence;
_extendFlushReplays = extendFlushReplays;
_useLogPersistence = useLogPersistence;
_useRadarModifiedBeacon = useRadarModifiedBeacon;
}
return self;
}

+ (RadarFeatureSettings *_Nullable)featureSettingsFromDictionary:(NSDictionary *)dict {
if (!dict) {
return [[RadarFeatureSettings alloc] initWithUsePersistence:NO extendFlushReplays:NO useLogPersistence:NO];
return [[RadarFeatureSettings alloc] initWithUsePersistence:NO
extendFlushReplays:NO
useLogPersistence:NO
useRadarModifiedBeacon:NO];
}

NSObject *usePersistenceObj = dict[@"usePersistence"];
Expand All @@ -42,15 +47,25 @@ + (RadarFeatureSettings *_Nullable)featureSettingsFromDictionary:(NSDictionary *
if (useLogPersistenceObj && [useLogPersistenceObj isKindOfClass:[NSNumber class]]) {
useLogPersistence = [(NSNumber *)useLogPersistenceObj boolValue];
}

NSObject *useRadarModifiedBeaconObj = dict[@"useRadarModifiedBeacon"];
BOOL useRadarModifiedBeacon = NO;
if (useRadarModifiedBeaconObj && [useRadarModifiedBeaconObj isKindOfClass:[NSNumber class]]) {
useRadarModifiedBeacon = [(NSNumber *)useRadarModifiedBeaconObj boolValue];
}

return [[RadarFeatureSettings alloc] initWithUsePersistence:usePersistence extendFlushReplays:extendFlushReplays useLogPersistence:useLogPersistence];
return [[RadarFeatureSettings alloc] initWithUsePersistence:usePersistence
extendFlushReplays:extendFlushReplays
useLogPersistence:useLogPersistence
useRadarModifiedBeacon:useRadarModifiedBeacon];
}

- (NSDictionary *)dictionaryValue {
NSMutableDictionary *dict = [NSMutableDictionary new];
[dict setValue:@(self.usePersistence) forKey:@"usePersistence"];
[dict setValue:@(self.extendFlushReplays) forKey:@"extendFlushReplays"];
[dict setValue:@(self.useLogPersistence) forKey:@"useLogPersistence"];
[dict setValue:@(self.useRadarModifiedBeacon) forKey:@"useRadarModifiedBeacon"];

return dict;
}
Expand Down
144 changes: 112 additions & 32 deletions RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ - (void)removePendingNotificationsWithCompletionHandler:(void (^)(void))completi
}

- (void)replaceSyncedBeacons:(NSArray<RadarBeacon *> *)beacons {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

[self removeSyncedBeacons];

BOOL tracking = [RadarSettings tracking];
Expand Down Expand Up @@ -617,6 +621,10 @@ - (void)replaceSyncedBeacons:(NSArray<RadarBeacon *> *)beacons {
}

- (void)replaceSyncedBeaconUUIDs:(NSArray<NSString *> *)uuids {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

[self removeSyncedBeacons];

BOOL tracking = [RadarSettings tracking];
Expand Down Expand Up @@ -645,6 +653,10 @@ - (void)replaceSyncedBeaconUUIDs:(NSArray<NSString *> *)uuids {
}

- (void)removeSyncedBeacons {
if ([RadarSettings useRadarModifiedBeacon]) {
return;
}

for (CLRegion *region in self.locationManager.monitoredRegions) {
if ([region.identifier hasPrefix:kSyncBeaconUUIDIdentifierPrefix]) {
[self.locationManager stopMonitoringForRegion:region];
Expand Down Expand Up @@ -843,42 +855,110 @@ - (void)sendLocation:(CLLocation *)location stopped:(BOOL)stopped source:(RadarL
self.sending = YES;

RadarTrackingOptions *options = [Radar getTrackingOptions];
if (options.beacons) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Searching for nearby beacons"];

if (source != RadarLocationSourceBeaconEnter && source != RadarLocationSourceBeaconExit && source != RadarLocationSourceMockLocation &&

if ([RadarSettings useRadarModifiedBeacon]) {
void (^callTrackAPI)(NSArray<RadarBeacon *> *_Nullable) = ^(NSArray<RadarBeacon *> *_Nullable beacons) {
[[RadarAPIClient sharedInstance] trackWithLocation:location
stopped:stopped
foreground:[RadarUtils foreground]
source:source
replayed:replayed
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
self.sending = NO;

[self updateTrackingFromMeta:config.meta];
[RadarSettings setFeatureSettings:config.meta.featureSettings];
[self replaceSyncedGeofences:nearbyGeofences];
}];
};

if (options.beacons &&
source != RadarLocationSourceBeaconEnter &&
source != RadarLocationSourceBeaconExit &&
source != RadarLocationSourceMockLocation &&
source != RadarLocationSourceManualLocation) {

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Searching for nearby beacons"];

[[RadarAPIClient sharedInstance]
searchBeaconsNear:location
radius:1000
limit:10
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarBeacon *> *_Nullable beacons, NSArray<NSString *> *_Nullable beaconUUIDs) {
if (beaconUUIDs && beaconUUIDs.count) {
[self replaceSyncedBeaconUUIDs:beaconUUIDs];
} else if (beacons && beacons.count) {
[self replaceSyncedBeacons:beacons];
}
}];
searchBeaconsNear:location
radius:1000
limit:10
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarBeacon *> *_Nullable beacons, NSArray<NSString *> *_Nullable beaconUUIDs) {
if (beaconUUIDs && beaconUUIDs.count) {
[self replaceSyncedBeaconUUIDs:beaconUUIDs];
[RadarUtils runOnMainThread:^{
[[RadarBeaconManager sharedInstance] rangeBeaconUUIDs:beaconUUIDs
completionHandler:^(RadarStatus status, NSArray<RadarBeacon *> *_Nullable beacons) {
if (status != RadarStatusSuccess || !beacons) {
callTrackAPI(nil);
return;
}

callTrackAPI(beacons);
}];
}];
} else if (beacons && beacons.count) {
[self replaceSyncedBeacons:beacons];
[RadarUtils runOnMainThread:^{
[[RadarBeaconManager sharedInstance] rangeBeacons:beacons
completionHandler:^(RadarStatus status, NSArray<RadarBeacon *> *_Nullable beacons) {
if (status != RadarStatusSuccess || !beacons) {
callTrackAPI(nil);

return;
}

callTrackAPI(beacons);
}];
}];
} else {
callTrackAPI(@[]);
}
}];
} else {
callTrackAPI(nil);
}
} else {
if (options.beacons) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Searching for nearby beacons"];

if (source != RadarLocationSourceBeaconEnter && source != RadarLocationSourceBeaconExit && source != RadarLocationSourceMockLocation &&
source != RadarLocationSourceManualLocation) {
[[RadarAPIClient sharedInstance]
searchBeaconsNear:location
radius:1000
limit:10
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarBeacon *> *_Nullable beacons, NSArray<NSString *> *_Nullable beaconUUIDs) {
if (beaconUUIDs && beaconUUIDs.count) {
[self replaceSyncedBeaconUUIDs:beaconUUIDs];
} else if (beacons && beacons.count) {
[self replaceSyncedBeacons:beacons];
}
}];
}
}
}

[[RadarAPIClient sharedInstance] trackWithLocation:location
stopped:stopped
foreground:[RadarUtils foreground]
source:source
replayed:replayed
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
self.sending = NO;
if (status != RadarStatusSuccess || !config) {
return;
}

[self updateTrackingFromMeta:config.meta];
[RadarSettings setFeatureSettings:config.meta.featureSettings];
[self replaceSyncedGeofences:nearbyGeofences];
}];
[[RadarAPIClient sharedInstance] trackWithLocation:location
stopped:stopped
foreground:[RadarUtils foreground]
source:source
replayed:replayed
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, NSString *_Nullable token) {
self.sending = NO;
if (status != RadarStatusSuccess || !config) {
return;
}

[self updateTrackingFromMeta:config.meta];
[RadarSettings setFeatureSettings:config.meta.featureSettings];
[self replaceSyncedGeofences:nearbyGeofences];
}];
}
}

#pragma mark - CLLocationManagerDelegate
Expand Down
1 change: 1 addition & 0 deletions RadarSDK/RadarSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)setUserDebug:(BOOL)userDebug;
+ (void)updateLastAppOpenTime;
+ (NSDate *)lastAppOpenTime;
+ (BOOL)useRadarModifiedBeacon;
+ (BOOL)xPlatform;
+ (NSString *)xPlatformSDKType;
+ (NSString *)xPlatformSDKVersion;
Expand Down
4 changes: 4 additions & 0 deletions RadarSDK/RadarSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ + (NSDate *)lastAppOpenTime {
return lastAppOpenTime ? lastAppOpenTime : [NSDate dateWithTimeIntervalSince1970:0];
}

+ (BOOL)useRadarModifiedBeacon {
return [[self featureSettings] useRadarModifiedBeacon];
}

+ (BOOL)xPlatform {
return [[NSUserDefaults standardUserDefaults] stringForKey:kXPlatformSDKType] != nil &&
[[NSUserDefaults standardUserDefaults] stringForKey:kXPlatformSDKVersion];
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ + (NSNumber *)timeZoneOffset {
}

+ (NSString *)sdkVersion {
return @"3.10.1";
return @"3.11.0";
}

+ (NSString *)deviceId {
Expand Down

0 comments on commit 61758ab

Please sign in to comment.