Skip to content

Commit

Permalink
bump min deploy target to 12 (#414)
Browse files Browse the repository at this point in the history
* bump min deploy target to 12

* bump archivedDataWithRootObject calls to new interface

* copy over changes from shicheng/fence-2079-switch-from-unarchiveobjectwithdata-to

* remove uneeded nscoding prototype

* remove un-needed version gates

* edit white space

* try and marshal/unmarshal all logs

* bump to 3.19.1
  • Loading branch information
KennyHuRadar authored Nov 19, 2024
1 parent 6632c05 commit b4a1b32
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 69 deletions.
4 changes: 2 additions & 2 deletions RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.19.0'
s.version = '3.19.1'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => 'support@radar.com' }
s.platform = :ios
s.source = { :git => 'https://github.com/radarlabs/radar-sdk-ios.git', :tag => s.version.to_s }
s.source_files = ["RadarSDK/*.{h,m}", "RadarSDK/Internal/*.{h,m}", "RadarSDK/Include/*.h"]
s.module_name = 'RadarSDK'
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '12.0'
s.frameworks = 'CoreLocation'
s.requires_arc = true
s.license = { :type => 'Apache-2.0' }
Expand Down
16 changes: 8 additions & 8 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = RadarSDK/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -960,7 +960,7 @@
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
Expand All @@ -977,7 +977,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = RadarSDK/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -990,7 +990,7 @@
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
Expand Down Expand Up @@ -1065,8 +1065,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.19.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 3.19.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1123,8 +1123,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.19.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 3.19.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
4 changes: 1 addition & 3 deletions RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ - (void)updateTracking:(CLLocation *)location fromInitialize:(BOOL)fromInitializ
}
self.locationManager.desiredAccuracy = desiredAccuracy;

if (@available(iOS 11.0, *)) {
self.lowPowerLocationManager.showsBackgroundLocationIndicator = options.showBlueBar;
}
self.lowPowerLocationManager.showsBackgroundLocationIndicator = options.showBlueBar;

BOOL startUpdates = options.showBlueBar || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways;
BOOL stopped = [RadarState stopped];
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
Represents a debug log.
*/
@interface RadarLog : NSObject <NSCoding>
@interface RadarLog : NSObject <NSSecureCoding>

/**
The levels for debug logs.
Expand Down
4 changes: 4 additions & 0 deletions RadarSDK/RadarLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ - (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:_createdAt forKey:@"createdAt"];
}

+ (BOOL)supportsSecureCoding {
return YES;
}

@end
12 changes: 10 additions & 2 deletions RadarSDK/RadarLogBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ - (void)persistLogs {
for (NSString *file in files) {
NSString *filePath = [self.logFileDir stringByAppendingPathComponent:file];
NSData *fileData = [self.fileHandler readFileAtPath:filePath];
RadarLog *log = [NSKeyedUnarchiver unarchiveObjectWithData:fileData];
NSError *error;
RadarLog *log = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithObjects:[NSString class], [RadarLog class], [NSDate class], nil] fromData:fileData error:&error];
if (error) {
NSLog(@"Failed to unarchive log: %@", error);
}
if (log && log.message) {
[logs addObject:log];
}
Expand All @@ -122,7 +126,11 @@ - (void)persistLogs {

- (void)writeToFileStorage:(NSArray <RadarLog *> *)logs {
for (RadarLog *log in logs) {
NSData *logData = [NSKeyedArchiver archivedDataWithRootObject:log];
NSError *error;
NSData *logData = [NSKeyedArchiver archivedDataWithRootObject:log requiringSecureCoding:YES error:&error];
if (error) {
NSLog(@"Failed to archive log: %@", error);
}
NSTimeInterval unixTimestamp = [log.createdAt timeIntervalSince1970];
// logs may be created in the same millisecond, so we append a counter to the end of the timestamp to "tiebreak"
NSString *unixTimestampString = [NSString stringWithFormat:@"%lld_%04d", (long long)unixTimestamp, fileCounter++];
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "Radar.h"

@interface RadarReplay : NSObject <NSCoding>
@interface RadarReplay : NSObject <NSSecureCoding>

@property (nonnull, copy, nonatomic, readonly) NSDictionary *replayParams;

Expand Down
4 changes: 4 additions & 0 deletions RadarSDK/RadarReplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ - (NSUInteger)hash {
return [self.replayParams hash];
}

+ (BOOL)supportsSecureCoding {
return YES;
}

@end
31 changes: 24 additions & 7 deletions RadarSDK/RadarReplayBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ - (void)writeNewReplayToBuffer:(NSMutableDictionary *)replayParams {
RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration];
if (sdkConfiguration.usePersistence) {
NSData *replaysData;
NSError *error;

// if buffer length is above 50, remove every fifth replay from the persisted buffer
if ([mutableReplayBuffer count] > 50) {
Expand All @@ -59,12 +60,16 @@ - (void)writeNewReplayToBuffer:(NSMutableDictionary *)replayParams {
[prunedBuffer addObject:mutableReplayBuffer[i]];
}
}
replaysData = [NSKeyedArchiver archivedDataWithRootObject:prunedBuffer];
replaysData = [NSKeyedArchiver archivedDataWithRootObject:prunedBuffer requiringSecureCoding:YES error:&error];
} else {
replaysData = [NSKeyedArchiver archivedDataWithRootObject:mutableReplayBuffer];
replaysData = [NSKeyedArchiver archivedDataWithRootObject:mutableReplayBuffer requiringSecureCoding:YES error:&error];
}
if (error) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Error archiving replays"];
return;
} else {
[[NSUserDefaults standardUserDefaults] setObject:replaysData forKey:@"radar-replays"];
}

[[NSUserDefaults standardUserDefaults] setObject:replaysData forKey:@"radar-replays"];
}
}

Expand Down Expand Up @@ -150,14 +155,26 @@ - (void)removeReplaysFromBuffer:(NSArray<RadarReplay *> *)replays {
[mutableReplayBuffer removeObjectsInArray:replays];

// persist the updated buffer
NSData *replaysData = [NSKeyedArchiver archivedDataWithRootObject:mutableReplayBuffer];
[[NSUserDefaults standardUserDefaults] setObject:replaysData forKey:@"radar-replays"];
NSError *error;
NSData *replaysData = [NSKeyedArchiver archivedDataWithRootObject:mutableReplayBuffer requiringSecureCoding:YES error:&error];
if (error) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Error archiving replays"];
return;
} else {
[[NSUserDefaults standardUserDefaults] setObject:replaysData forKey:@"radar-replays"];
}
}

- (void)loadReplaysFromPersistentStore {
NSData *replaysData = [[NSUserDefaults standardUserDefaults] objectForKey:@"radar-replays"];
if (replaysData) {
NSArray *replays = [NSKeyedUnarchiver unarchiveObjectWithData:replaysData];
NSError *error;
NSSet *allowedClasses = [NSSet setWithObjects:[NSArray class], [RadarReplay class], [NSDictionary class], [NSString class], [NSNumber class], nil];
NSArray<RadarReplay *> *replays = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowedClasses fromData:replaysData error:&error];
if (error) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Error unarchiving replays"];
return;
}
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Loaded replays | length = %lu", (unsigned long)[replays count]]];
mutableReplayBuffer = [NSMutableArray arrayWithArray:replays];
}
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.19.0";
return @"3.19.1";
}

+ (NSString *)deviceId {
Expand Down
75 changes: 35 additions & 40 deletions RadarSDK/RadarVerificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,55 +230,50 @@ - (void)startTrackingVerifiedWithInterval:(NSTimeInterval)interval beacons:(BOOL
self.startedInterval = interval;
self.startedBeacons = beacons;

if (@available(iOS 12.0, *)) {
if (!_monitor) {
_monitor = nw_path_monitor_create();
if (!_monitor) {
_monitor = nw_path_monitor_create();

nw_path_monitor_set_queue(_monitor, dispatch_get_main_queue());
nw_path_monitor_set_queue(_monitor, dispatch_get_main_queue());

nw_path_monitor_set_update_handler(_monitor, ^(nw_path_t path) {
if (nw_path_get_status(path) == nw_path_status_satisfied) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Network connected"];
} else {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Network disconnected"];
}

NSString *ips = [self getIPs];
BOOL changed = NO;

if (!self.lastIPs) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"First time getting IPs | ips = %@", ips]];
changed = NO;
} else if (!ips || [ips isEqualToString:@"error"]) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Error getting IPs | ips = %@", ips]];
changed = YES;
} else if (![ips isEqualToString:self.lastIPs]) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"IPs changed | ips = %@; lastIPs = %@", ips, self.lastIPs]];
changed = YES;
} else {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"IPs unchanged"];
}
self.lastIPs = ips;
nw_path_monitor_set_update_handler(_monitor, ^(nw_path_t path) {
if (nw_path_get_status(path) == nw_path_status_satisfied) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Network connected"];
} else {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"Network disconnected"];
}

if (changed) {
[self callTrackVerified];
}
});

nw_path_monitor_start(_monitor);
}
NSString *ips = [self getIPs];
BOOL changed = NO;

if (!self.lastIPs) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"First time getting IPs | ips = %@", ips]];
changed = NO;
} else if (!ips || [ips isEqualToString:@"error"]) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Error getting IPs | ips = %@", ips]];
changed = YES;
} else if (![ips isEqualToString:self.lastIPs]) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"IPs changed | ips = %@; lastIPs = %@", ips, self.lastIPs]];
changed = YES;
} else {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:@"IPs unchanged"];
}
self.lastIPs = ips;

if (changed) {
[self callTrackVerified];
}
});
nw_path_monitor_start(_monitor);
}

[self callTrackVerified];
}

- (void)stopTrackingVerified {
self.started = NO;

if (@available(iOS 12.0, *)) {
if (_monitor) {
nw_path_monitor_cancel(_monitor);
}

if (_monitor) {
nw_path_monitor_cancel(_monitor);
}

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(intervalFired) object:nil];
Expand Down
4 changes: 2 additions & 2 deletions RadarSDKMotion.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = 'RadarSDKMotion'
s.version = '3.19.0'
s.version = '3.19.1'
s.summary = 'Motion detection plugin for RadarSDK, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => 'support@radar.com' }
s.platform = :ios
s.source = { :git => 'https://github.com/radarlabs/radar-sdk-ios.git', :tag => s.version.to_s }
s.source_files = ["RadarSDKMotion/RadarSDKMotion/*.{h,m}", "RadarSDKMotion/RadarSDKMotion/Include/*.h"]
s.module_name = 'RadarSDKMotion'
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '12.0'
s.frameworks = 'CoreMotion'
s.requires_arc = true
s.license = { :type => 'Apache-2.0' }
Expand Down
21 changes: 19 additions & 2 deletions RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "RadarTestUtils.h"
#import "RadarTripOptions.h"
#import "RadarFileStorage.h"

#import "RadarReplayBuffer.h"

@interface RadarSDKTests : XCTestCase

Expand All @@ -30,6 +30,7 @@ @interface RadarSDKTests : XCTestCase
@property (nonatomic, strong) RadarFileStorage *fileSystem;
@property (nonatomic, strong) NSString *testFilePath;
@property (nonatomic, strong) RadarLogBuffer *logBuffer;
@property (nonatomic, strong) RadarReplayBuffer *replayBuffer;
@end

@implementation RadarSDKTests
Expand Down Expand Up @@ -299,7 +300,7 @@ - (void)setUp {
self.testFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testfile"];
[[RadarLogBuffer sharedInstance]clearBuffer];
[[RadarLogBuffer sharedInstance]setPersistentLogFeatureFlag:YES];

[[RadarReplayBuffer sharedInstance]clearBuffer];
}

- (void)tearDown {
Expand Down Expand Up @@ -1491,6 +1492,22 @@ - (void)test_RadarLogBuffer_purge {
[[RadarLogBuffer sharedInstance]clearBuffer];
}

- (void)test_RadarReplayBuffer_writeAndRead {
RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration];
sdkConfiguration.usePersistence = true;
[RadarSettings setSdkConfiguration:sdkConfiguration];

CLLocation *location = [[CLLocation alloc] initWithLatitude:0.1 longitude:0.1];
NSMutableDictionary * params = [RadarTestUtils createTrackParamWithLocation:location stopped:YES foreground:YES source:RadarLocationSourceGeofenceEnter replayed:YES beacons:[NSArray arrayWithObject:[RadarBeacon alloc]] verified:YES attestationString:@"attestationString" keyId:@"keyID" attestationError:@"attestationError" encrypted:YES expectedCountryCode:@"CountryCode" expectedStateCode:@"StateCode"];

[[RadarReplayBuffer sharedInstance] writeNewReplayToBuffer:params];
[[RadarReplayBuffer sharedInstance] setValue:NULL forKey:@"mutableReplayBuffer"];
[[RadarReplayBuffer sharedInstance] loadReplaysFromPersistentStore];
NSMutableArray<RadarReplay *> *mutableReplayBuffer = [[RadarReplayBuffer sharedInstance] valueForKey:@"mutableReplayBuffer"];
XCTAssertEqual(mutableReplayBuffer.count, 1);
XCTAssertEqualObjects(mutableReplayBuffer.firstObject.replayParams, params);
}

- (void)test_RadarSdkConfiguration {
RadarSdkConfiguration *sdkConfiguration = [[RadarSdkConfiguration alloc] initWithDict:@{
@"logLevel": @"warning",
Expand Down
Loading

0 comments on commit b4a1b32

Please sign in to comment.