diff --git a/RadarSDK/Include/RadarGeofence.h b/RadarSDK/Include/RadarGeofence.h index a6f90da09..4a831315c 100644 --- a/RadarSDK/Include/RadarGeofence.h +++ b/RadarSDK/Include/RadarGeofence.h @@ -51,6 +51,8 @@ */ @property (nullable, copy, nonatomic, readonly) RadarOperatingHours *operatingHours; +@property (nonatomic, readonly) float altitude; + + (NSArray *_Nullable)arrayForGeofences:(NSArray *_Nullable)geofences; - (NSDictionary *_Nonnull)dictionaryValue; diff --git a/RadarSDK/Include/RadarUser.h b/RadarSDK/Include/RadarUser.h index 77976e32c..92201b9db 100644 --- a/RadarSDK/Include/RadarUser.h +++ b/RadarSDK/Include/RadarUser.h @@ -65,6 +65,8 @@ typedef NS_ENUM(NSInteger, RadarActivityType); */ @property (nullable, copy, nonatomic, readonly) NSArray *geofences; +@property (nullable, copy, nonatomic, readonly) NSArray *latestGeofencesDwelled; + /** The user's current place. May be `nil` if the user is not at a place or if Places is not enabled. diff --git a/RadarSDK/RadarAPIClient.m b/RadarSDK/RadarAPIClient.m index 048abf30c..6810344bf 100644 --- a/RadarSDK/RadarAPIClient.m +++ b/RadarSDK/RadarAPIClient.m @@ -541,10 +541,20 @@ - (void)makeTrackRequestWithParams:(NSDictionary *)params RadarConfig *config = [RadarConfig fromDictionary:res]; id eventsObj = res[@"events"]; + id locationMetadataObj = res[@"locationMetadata"]; id userObj = res[@"user"]; if ([userObj isKindOfClass:[NSDictionary class]]) { NSMutableDictionary *mutableUserObj = [userObj mutableCopy]; - mutableUserObj[@"metadata"] = locationMetadata; + if (locationMetadataObj && [locationMetadataObj isKindOfClass:[NSDictionary class]]) { + NSMutableDictionary *mutableLocationMetadata = [locationMetadata mutableCopy]; + for (NSString *key in locationMetadataObj) { + mutableLocationMetadata[key] = locationMetadataObj[key]; + } + mutableUserObj[@"metadata"] = mutableLocationMetadata; + } else { + mutableUserObj[@"metadata"] = locationMetadata; + } + userObj = mutableUserObj; } id nearbyGeofencesObj = res[@"nearbyGeofences"]; diff --git a/RadarSDK/RadarGeofence+Internal.h b/RadarSDK/RadarGeofence+Internal.h index 5c87ebc7a..c15ee877f 100644 --- a/RadarSDK/RadarGeofence+Internal.h +++ b/RadarSDK/RadarGeofence+Internal.h @@ -17,7 +17,8 @@ externalId:(NSString *_Nullable)externalId metadata:(NSDictionary *_Nullable)metadata operatingHours:(RadarOperatingHours *_Nullable)operatingHours - geometry:(RadarGeofenceGeometry *_Nonnull)geometry; + geometry:(RadarGeofenceGeometry *_Nonnull)geometry + altitude:(float)altitude; - (instancetype _Nullable)initWithObject:(id _Nonnull)object; @end diff --git a/RadarSDK/RadarGeofence.m b/RadarSDK/RadarGeofence.m index 4713215de..9927242da 100644 --- a/RadarSDK/RadarGeofence.m +++ b/RadarSDK/RadarGeofence.m @@ -38,7 +38,8 @@ - (instancetype _Nullable)initWithId:(NSString *)_id externalId:(NSString *_Nullable)externalId metadata:(NSDictionary *_Nullable)metadata operatingHours: (RadarOperatingHours *_Nullable) operatingHours - geometry:(RadarGeofenceGeometry *_Nonnull)geometry { + geometry:(RadarGeofenceGeometry *_Nonnull)geometry + altitude:(float)altitude { self = [super init]; if (self) { __id = _id; @@ -48,6 +49,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id _metadata = metadata; _operatingHours = operatingHours; _geometry = geometry; + _altitude = altitude; } return self; } @@ -66,6 +68,7 @@ - (instancetype _Nullable)initWithObject:(id)object { NSDictionary *metadata; RadarOperatingHours *operatingHours; RadarGeofenceGeometry *geometry; + float altitude = 0.0; id idObj = dict[@"_id"]; if (idObj && [idObj isKindOfClass:[NSString class]]) { @@ -139,7 +142,12 @@ - (instancetype _Nullable)initWithObject:(id)object { } } - return [[RadarGeofence alloc] initWithId:_id description:description tag:tag externalId:externalId metadata:metadata operatingHours:operatingHours geometry:geometry]; + id altitudeObj = dict[@"altitude"]; + if (altitudeObj && [altitudeObj isKindOfClass:[NSNumber class]]) { + altitude = [((NSNumber *)altitudeObj) floatValue]; + } + + return [[RadarGeofence alloc] initWithId:_id description:description tag:tag externalId:externalId metadata:metadata operatingHours:operatingHours geometry:geometry altitude:altitude]; } - (NSMutableArray *)getPolygonCoordinates:(NSDictionary *)dict { @@ -239,6 +247,9 @@ - (NSDictionary *)dictionaryValue { } [dict setValue:@"Polygon" forKey:@"type"]; } + if (self.altitude) { + [dict setValue:@(self.altitude) forKey:@"altitude"]; + } return dict; } diff --git a/RadarSDK/RadarUser+Internal.h b/RadarSDK/RadarUser+Internal.h index aea5a47b1..7549ddf48 100644 --- a/RadarSDK/RadarUser+Internal.h +++ b/RadarSDK/RadarUser+Internal.h @@ -35,7 +35,8 @@ trip:(RadarTrip *_Nullable)trip debug:(BOOL)debug fraud:(RadarFraud *_Nullable)fraud - altitude:(double)altitude; + altitude:(double)altitude + latestGeofencesDwelled:(nullable NSArray *)latestGeofencesDwelled; - (instancetype _Nullable)initWithObject:(id _Nonnull)object; @end diff --git a/RadarSDK/RadarUser.m b/RadarSDK/RadarUser.m index 911b9adc9..9887222a6 100644 --- a/RadarSDK/RadarUser.m +++ b/RadarSDK/RadarUser.m @@ -43,7 +43,8 @@ - (instancetype _Nullable)initWithId:(NSString *)_id trip:(RadarTrip *_Nullable)trip debug:(BOOL)debug fraud:(RadarFraud *_Nullable)fraud - altitude:(double)altitude { + altitude:(double)altitude + latestGeofencesDwelled:(nullable NSArray *)latestGeofencesDwelled { self = [super init]; if (self) { __id = _id; @@ -70,6 +71,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id _debug = debug; _fraud = fraud; _altitude = altitude; + _latestGeofencesDwelled = latestGeofencesDwelled; } return self; } @@ -89,6 +91,7 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object { CLLocation *location; RadarActivityType activityType = RadarActivityTypeUnknown; NSArray *geofences; + NSArray *latestGeofencesDwelled; RadarPlace *place; NSArray *beacons; BOOL stopped = NO; @@ -195,6 +198,11 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object { geofences = [RadarGeofence geofencesFromObject:geofencesObj]; } + id latestGeofencesDwelledObj = dict[@"latestGeofencesDwelled"]; + if (latestGeofencesDwelledObj && [latestGeofencesDwelledObj isKindOfClass:[NSArray class]]) { + latestGeofencesDwelled = [RadarGeofence geofencesFromObject:latestGeofencesDwelledObj]; + } + id placeObj = dict[@"place"]; place = [[RadarPlace alloc] initWithObject:placeObj]; @@ -328,7 +336,8 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object { trip:trip debug:debug fraud:fraud - altitude:altitude]; + altitude:altitude + latestGeofencesDwelled:latestGeofencesDwelled]; } return nil; @@ -349,6 +358,8 @@ - (NSDictionary *)dictionaryValue { [dict setValue:[Radar stringForActivityType:self.activityType] forKey:@"activityType"]; NSArray *geofencesArr = [RadarGeofence arrayForGeofences:self.geofences]; [dict setValue:geofencesArr forKey:@"geofences"]; + NSArray *latestGeofencesDwelledArr = [RadarGeofence arrayForGeofences:self.latestGeofencesDwelled]; + [dict setValue:latestGeofencesDwelledArr forKey:@"latestGeofencesDwelled"]; if (self.place) { NSDictionary *placeDict = [self.place dictionaryValue]; [dict setValue:placeDict forKey:@"place"];