-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use none-deprecated archive functions when possible #394
Changes from 2 commits
7e87e5e
830c9a8
683c9b1
7c25ead
8d4065b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,8 @@ - (NSUInteger)hash { | |
return [self.replayParams hash]; | ||
} | ||
|
||
+ (BOOL)supportsSecureCoding { | ||
return YES; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
#import "RadarTestUtils.h" | ||
#import "RadarTripOptions.h" | ||
#import "RadarFileStorage.h" | ||
|
||
#import "RadarReplayBuffer.h" | ||
|
||
@interface RadarSDKTests : XCTestCase | ||
|
||
|
@@ -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 | ||
|
@@ -299,7 +300,7 @@ - (void)setUp { | |
self.testFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testfile"]; | ||
[[RadarLogBuffer sharedInstance]clearBuffer]; | ||
[[RadarLogBuffer sharedInstance]setPersistentLogFeatureFlag:YES]; | ||
|
||
[[RadarReplayBuffer sharedInstance]clearBuffer]; | ||
} | ||
|
||
- (void)tearDown { | ||
|
@@ -1489,6 +1490,22 @@ - (void)test_RadarLogBuffer_purge { | |
[[RadarLogBuffer sharedInstance]clearBuffer]; | ||
} | ||
|
||
- (void)test_RadarReplayBuffer_writeAndRead { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for adding this test |
||
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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,181 @@ + (NSDictionary *)jsonDictionaryFromResource:(NSString *)resource { | |
return jsonDict; | ||
} | ||
|
||
+ (NSMutableDictionary *)createTrackParamWithLocation:(CLLocation *_Nonnull)location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess using the default values returned by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added function docstring in the header file for this behaviour |
||
stopped:(BOOL)stopped | ||
foreground:(BOOL)foreground | ||
source:(RadarLocationSource)source | ||
replayed:(BOOL)replayed | ||
beacons:(NSArray<RadarBeacon *> *_Nullable)beacons | ||
verified:(BOOL)verified | ||
attestationString:(NSString *_Nullable)attestationString | ||
keyId:(NSString *_Nullable)keyId | ||
attestationError:(NSString *_Nullable)attestationError | ||
encrypted:(BOOL)encrypted | ||
expectedCountryCode:(NSString * _Nullable)expectedCountryCode | ||
expectedStateCode:(NSString * _Nullable)expectedStateCode{ | ||
NSMutableDictionary *params = [NSMutableDictionary new]; | ||
BOOL anonymous = [RadarSettings anonymousTrackingEnabled]; | ||
params[@"anonymous"] = @(anonymous); | ||
if (anonymous) { | ||
params[@"deviceId"] = @"anonymous"; | ||
params[@"geofenceIds"] = [RadarState geofenceIds]; | ||
params[@"placeId"] = [RadarState placeId]; | ||
params[@"regionIds"] = [RadarState regionIds]; | ||
params[@"beaconIds"] = [RadarState beaconIds]; | ||
} else { | ||
params[@"id"] = [RadarSettings _id]; | ||
params[@"installId"] = [RadarSettings installId]; | ||
params[@"userId"] = [RadarSettings userId]; | ||
params[@"deviceId"] = [RadarUtils deviceId]; | ||
params[@"description"] = [RadarSettings __description]; | ||
params[@"metadata"] = [RadarSettings metadata]; | ||
NSString *sessionId = [RadarSettings sessionId]; | ||
if (sessionId) { | ||
params[@"sessionId"] = sessionId; | ||
} | ||
} | ||
params[@"latitude"] = @(location.coordinate.latitude); | ||
params[@"longitude"] = @(location.coordinate.longitude); | ||
CLLocationAccuracy accuracy = location.horizontalAccuracy; | ||
if (accuracy <= 0) { | ||
accuracy = 1; | ||
} | ||
params[@"accuracy"] = @(accuracy); | ||
params[@"altitude"] = @(location.altitude); | ||
params[@"verticalAccuracy"] = @(location.verticalAccuracy); | ||
params[@"speed"] = @(location.speed); | ||
params[@"speedAccuracy"] = @(location.speedAccuracy); | ||
params[@"course"] = @(location.course); | ||
if (@available(iOS 13.4, *)) { | ||
params[@"courseAccuracy"] = @(location.courseAccuracy); | ||
} | ||
if (location.floor) { | ||
params[@"floorLevel"] = @(location.floor.level); | ||
} | ||
long nowMs = (long)([NSDate date].timeIntervalSince1970 * 1000); | ||
if (!foreground) { | ||
long timeInMs = (long)(location.timestamp.timeIntervalSince1970 * 1000); | ||
params[@"updatedAtMsDiff"] = @(nowMs - timeInMs); | ||
} | ||
params[@"foreground"] = @(foreground); | ||
params[@"stopped"] = @(stopped); | ||
params[@"replayed"] = @(replayed); | ||
params[@"deviceType"] = [RadarUtils deviceType]; | ||
params[@"deviceMake"] = [RadarUtils deviceMake]; | ||
params[@"sdkVersion"] = [RadarUtils sdkVersion]; | ||
params[@"deviceModel"] = [RadarUtils deviceModel]; | ||
params[@"deviceOS"] = [RadarUtils deviceOS]; | ||
params[@"country"] = [RadarUtils country]; | ||
params[@"timeZoneOffset"] = [RadarUtils timeZoneOffset]; | ||
params[@"source"] = [Radar stringForLocationSource:source]; | ||
if ([RadarSettings xPlatform]) { | ||
params[@"xPlatformType"] = [RadarSettings xPlatformSDKType]; | ||
params[@"xPlatformSDKVersion"] = [RadarSettings xPlatformSDKVersion]; | ||
} else { | ||
params[@"xPlatformType"] = @"Native"; | ||
} | ||
NSMutableArray<NSString *> *fraudFailureReasons = [NSMutableArray new]; | ||
if (@available(iOS 15.0, *)) { | ||
CLLocationSourceInformation *sourceInformation = location.sourceInformation; | ||
if (sourceInformation) { | ||
if (sourceInformation.isSimulatedBySoftware) { | ||
params[@"mocked"] = @(YES); | ||
[fraudFailureReasons addObject:@"fraud_mocked_from_mock_provider"]; | ||
} | ||
if (sourceInformation.isProducedByAccessory) { | ||
[fraudFailureReasons addObject:@"fraud_mocked_produced_by_accessory"]; | ||
} | ||
} | ||
} | ||
|
||
RadarTripOptions *tripOptions = Radar.getTripOptions; | ||
|
||
if (tripOptions) { | ||
NSMutableDictionary *tripParams = [NSMutableDictionary new]; | ||
tripParams[@"version"] = @("2"); | ||
[tripParams setValue:tripOptions.externalId forKey:@"externalId"]; | ||
[tripParams setValue:tripOptions.metadata forKey:@"metadata"]; | ||
[tripParams setValue:tripOptions.destinationGeofenceTag forKey:@"destinationGeofenceTag"]; | ||
[tripParams setValue:tripOptions.destinationGeofenceExternalId forKey:@"destinationGeofenceExternalId"]; | ||
[tripParams setValue:[Radar stringForMode:tripOptions.mode] forKey:@"mode"]; | ||
params[@"tripOptions"] = tripParams; | ||
} | ||
|
||
RadarTrackingOptions *options = [Radar getTrackingOptions]; | ||
if (options.syncGeofences) { | ||
params[@"nearbyGeofences"] = @(YES); | ||
} | ||
if (beacons) { | ||
params[@"beacons"] = [RadarBeacon arrayForBeacons:beacons]; | ||
} | ||
NSString *locationAuthorization = [RadarUtils locationAuthorization]; | ||
if (locationAuthorization) { | ||
params[@"locationAuthorization"] = locationAuthorization; | ||
} | ||
NSString *locationAccuracyAuthorization = [RadarUtils locationAccuracyAuthorization]; | ||
if (locationAccuracyAuthorization) { | ||
params[@"locationAccuracyAuthorization"] = locationAccuracyAuthorization; | ||
} | ||
params[@"notificationAuthorization"] = [RadarState notificationPermissionGranted] ? @"true" : @"false"; | ||
|
||
params[@"trackingOptions"] = [options dictionaryValue]; | ||
|
||
BOOL usingRemoteTrackingOptions = RadarSettings.tracking && RadarSettings.remoteTrackingOptions; | ||
params[@"usingRemoteTrackingOptions"] = @(usingRemoteTrackingOptions); | ||
|
||
params[@"verified"] = @(verified); | ||
if (verified) { | ||
params[@"attestationString"] = attestationString; | ||
params[@"keyId"] = keyId; | ||
params[@"attestationError"] = attestationError; | ||
params[@"encrypted"] = @(encrypted); | ||
BOOL jailbroken = [[RadarVerificationManager sharedInstance] isJailbroken]; | ||
params[@"compromised"] = @(jailbroken); | ||
if (jailbroken) { | ||
[fraudFailureReasons addObject:@"fraud_compromised_jailbroken"]; | ||
} | ||
if (expectedCountryCode) { | ||
params[@"expectedCountryCode"] = expectedCountryCode; | ||
} | ||
if (expectedStateCode) { | ||
params[@"expectedStateCode"] = expectedStateCode; | ||
} | ||
} | ||
params[@"appId"] = [[NSBundle mainBundle] bundleIdentifier]; | ||
RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration]; | ||
if (sdkConfiguration.useLocationMetadata) { | ||
NSMutableDictionary *locationMetadata = [NSMutableDictionary new]; | ||
locationMetadata[@"motionActivityData"] = [RadarState lastMotionActivityData]; | ||
locationMetadata[@"heading"] = [RadarState lastHeadingData]; | ||
locationMetadata[@"speed"] = @(location.speed); | ||
locationMetadata[@"speedAccuracy"] = @(location.speedAccuracy); | ||
locationMetadata[@"course"] = @(location.course); | ||
|
||
if (@available(iOS 13.4, *)) { | ||
locationMetadata[@"courseAccuracy"] = @(location.courseAccuracy); | ||
} | ||
|
||
locationMetadata[@"battery"] = @([[UIDevice currentDevice] batteryLevel]); | ||
locationMetadata[@"altitude"] = @(location.altitude); | ||
|
||
if (@available(iOS 15, *)) { | ||
locationMetadata[@"ellipsoidalAltitude"] = @(location.ellipsoidalAltitude); | ||
locationMetadata[@"isProducedByAccessory"] = @([location.sourceInformation isProducedByAccessory]); | ||
locationMetadata[@"isSimulatedBySoftware"] = @([location.sourceInformation isSimulatedBySoftware]); | ||
} | ||
locationMetadata[@"floor"] = @([location.floor level]); | ||
|
||
params[@"locationMetadata"] = locationMetadata; | ||
} | ||
|
||
params[@"fraudFailureReasons"] = fraudFailureReasons; | ||
|
||
// added after API call fail | ||
params[@"replayed"] = @(YES); | ||
params[@"updatedAtMs"] = @(nowMs); | ||
|
||
return params; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused about iOS 11 version gate since NSSecureCoding is available from iOS 6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
archivedDataWithRootObject: requireingSecureCoding:
function is only introduced in iOS 11.0. the function that we were using (without the second param) is the one raising security alerts.