Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.20.1'
s.version = '3.20.2'
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
12 changes: 10 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
78D8CE3C23AD78A1009E91F5 /* geocode.json in Resources */ = {isa = PBXBuildFile; fileRef = 78D8CE3B23AD78A1009E91F5 /* geocode.json */; };
78D8CE3E23AD7FEE009E91F5 /* geocode_ip.json in Resources */ = {isa = PBXBuildFile; fileRef = 78D8CE3D23AD7FEE009E91F5 /* geocode_ip.json */; };
8227EF0C2CDAB69B00C47290 /* RadarRouteMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8227EF0B2CDAB69B00C47290 /* RadarRouteMode.m */; };
8243AA0A2D40275E00914BDE /* geocode_london.json in Resources */ = {isa = PBXBuildFile; fileRef = 8243AA092D40275E00914BDE /* geocode_london.json */; };
8243AA0B2D40275E00914BDE /* geocode_darwin.json in Resources */ = {isa = PBXBuildFile; fileRef = 8243AA082D40275E00914BDE /* geocode_darwin.json */; };
825732512B72BE1900DF8B88 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 825732502B72BE1900DF8B88 /* PrivacyInfo.xcprivacy */; };
825732522B72BE1900DF8B88 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 825732502B72BE1900DF8B88 /* PrivacyInfo.xcprivacy */; };
82D04ABB29722ED20036619F /* RadarReplay.h in Headers */ = {isa = PBXBuildFile; fileRef = 82D04AB829722ED20036619F /* RadarReplay.h */; };
Expand Down Expand Up @@ -205,6 +207,8 @@
78D8CE3B23AD78A1009E91F5 /* geocode.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = geocode.json; sourceTree = "<group>"; };
78D8CE3D23AD7FEE009E91F5 /* geocode_ip.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = geocode_ip.json; sourceTree = "<group>"; };
8227EF0B2CDAB69B00C47290 /* RadarRouteMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarRouteMode.m; sourceTree = "<group>"; };
8243AA082D40275E00914BDE /* geocode_darwin.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = geocode_darwin.json; sourceTree = "<group>"; };
8243AA092D40275E00914BDE /* geocode_london.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = geocode_london.json; sourceTree = "<group>"; };
825732502B72BE1900DF8B88 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
82D04AB829722ED20036619F /* RadarReplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarReplay.h; sourceTree = "<group>"; };
82D04AB929722ED20036619F /* RadarReplayBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarReplayBuffer.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -432,6 +436,8 @@
DD103213237F1778003DD408 /* Resources */ = {
isa = PBXGroup;
children = (
8243AA082D40275E00914BDE /* geocode_darwin.json */,
8243AA092D40275E00914BDE /* geocode_london.json */,
53B3B26A23EE41B400080818 /* context.json */,
F65AF72B2C10B242002BA009 /* get_config_response.json */,
966D885F288F7404008C0D00 /* conversion_event.json */,
Expand Down Expand Up @@ -818,6 +824,8 @@
DD4D4D2523E648D000D36C1D /* search_autocomplete.json in Resources */,
DD5E35E1238205FF002D93FF /* events_verification.json in Resources */,
825732512B72BE1900DF8B88 /* PrivacyInfo.xcprivacy in Resources */,
8243AA0A2D40275E00914BDE /* geocode_london.json in Resources */,
8243AA0B2D40275E00914BDE /* geocode_darwin.json in Resources */,
96A0AC2728A4066D00B41D40 /* search_places_chain_metadata.json in Resources */,
53B3B26B23EE41B400080818 /* context.json in Resources */,
78D8CE3C23AD78A1009E91F5 /* geocode.json in Resources */,
Expand Down Expand Up @@ -1062,7 +1070,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 3.20.1;
MARKETING_VERSION = 3.20.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1120,7 +1128,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 3.20.1;
MARKETING_VERSION = 3.20.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
38 changes: 22 additions & 16 deletions RadarSDK/RadarTimeZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
#import "RadarTimeZone.h"
#import "RadarUtils.h"

NSDateFormatter *_timezoneDateFormatter = nil;
NSDateFormatter * timezoneDateFormatter(void) {
if (_timezoneDateFormatter == nil) {
_timezoneDateFormatter = [[NSDateFormatter alloc] init];
_timezoneDateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[_timezoneDateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
}
return _timezoneDateFormatter;
}

@implementation RadarTimeZone

- (instancetype _Nullable)initWithObject:(id)object {
Expand All @@ -28,7 +18,7 @@ - (instancetype _Nullable)initWithObject:(id)object {

NSDictionary *dict = (NSDictionary *)object;

id idObj = dict[@"_id"];
id idObj = dict[@"id"];
if ([idObj isKindOfClass:[NSString class]]) {
__id = (NSString *)idObj;
}
Expand All @@ -45,8 +35,10 @@ - (instancetype _Nullable)initWithObject:(id)object {

id currentTimeObj = dict[@"currentTime"];
if (currentTimeObj && [currentTimeObj isKindOfClass:[NSString class]]) {

_currentTime = [timezoneDateFormatter() dateFromString:(NSString *)currentTimeObj];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
_currentTime = [formatter dateFromString:(NSString *)currentTimeObj];
}

id utcOffsetObj = dict[@"utcOffset"];
Expand All @@ -67,9 +59,23 @@ - (NSDictionary *)dictionaryValue {
dict[@"_id"] = self._id;
dict[@"name"] = self.name;
dict[@"code"] = self.code;
dict[@"currentTime"] = [timezoneDateFormatter() stringFromDate:self.currentTime];
dict[@"utcOffset"] = @(self.utcOffset);
dict[@"dstOffset"] = @(self.dstOffset);

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
NSTimeZone *tz = nil;
if (self._id) {
tz = [NSTimeZone timeZoneWithName:self._id];
}
if (!tz) {
tz = [NSTimeZone timeZoneForSecondsFromGMT:self.utcOffset * 3600];
}
formatter.timeZone = tz;

dict[@"currentTime"] = [formatter stringFromDate:self.currentTime];
dict[@"utcOffset"] = @(self.utcOffset);
dict[@"dstOffset"] = @(self.dstOffset);

return dict;
}

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.20.1";
return @"3.20.2";
}

+ (NSString *)deviceId {
Expand Down
2 changes: 1 addition & 1 deletion RadarSDKMotion.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDKMotion'
s.version = '3.20.1'
s.version = '3.20.2'
s.summary = 'Motion detection plugin for RadarSDK, 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 RadarSDKMotion/RadarSDKMotion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 3.20.1;
MARKETING_VERSION = 3.20.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -348,7 +348,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 3.20.1;
MARKETING_VERSION = 3.20.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
129 changes: 119 additions & 10 deletions RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1300,28 +1300,137 @@ - (void)test_Radar_reverseGeocodeLocation_error {
}

- (void)test_Radar_reverseGeocodeLocation_success {
self.permissionsHelperMock.mockLocationAuthorizationStatus = kCLAuthorizationStatusAuthorizedWhenInUse;
self.permissionsHelperMock.mockLocationAuthorizationStatus = kCLAuthorizationStatusAuthorizedWhenInUse;
self.apiHelperMock.mockStatus = RadarStatusSuccess;
self.apiHelperMock.mockResponse = [RadarTestUtils jsonDictionaryFromResource:@"geocode"];

CLLocation *location = [[CLLocation alloc] initWithLatitude:40.78382 longitude:-73.97536];

XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];

[Radar reverseGeocodeLocation:location
completionHandler:^(RadarStatus status, NSArray<RadarAddress *> *_Nullable addresses) {
XCTAssertEqual(status, RadarStatusSuccess);
AssertAddressesOk(addresses);

RadarAddress *address = addresses.firstObject;
XCTAssertNotNil(address.timeZone);
XCTAssertEqualObjects(address.timeZone._id, @"America/New_York");
XCTAssertEqualObjects(address.timeZone.name, @"Eastern Standard Time");
XCTAssertEqualObjects(address.timeZone.code, @"EST");
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)-18000);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
NSDateComponents *nycComponents = [[NSDateComponents alloc] init];
nycComponents.year = 2025;
nycComponents.month = 1; // January
nycComponents.day = 21;
nycComponents.hour = 17;
nycComponents.minute = 19;
nycComponents.second = 23;
NSDate *expectedNYCDate = [calendar dateFromComponents:nycComponents];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedNYCDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"-05:00"], @"NYC time should end with -05:00 but was: %@", currentTime);

[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30
handler:^(NSError *_Nullable error) {
if (error) {
XCTFail();
}
}];
}

- (void)test_Radar_reverseGeocode_london_timezone {
self.apiHelperMock.mockStatus = RadarStatusSuccess;
self.apiHelperMock.mockResponse = [RadarTestUtils jsonDictionaryFromResource:@"geocode"];
self.apiHelperMock.mockResponse = [RadarTestUtils jsonDictionaryFromResource:@"geocode_london"];

CLLocation *location = [[CLLocation alloc] initWithLatitude:40.78382 longitude:-73.97536];
CLLocation *location = [[CLLocation alloc] initWithLatitude:51.5074 longitude:-0.1278];

XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];

[Radar reverseGeocodeLocation:location
completionHandler:^(RadarStatus status, NSArray<RadarAddress *> *_Nullable addresses) {
XCTAssertEqual(status, RadarStatusSuccess);
AssertAddressesOk(addresses);
RadarAddress *address = addresses.firstObject;
XCTAssertNotNil(address.timeZone);
XCTAssertEqualObjects(address.timeZone._id, @"Europe/London");
XCTAssertEqualObjects(address.timeZone.name, @"Greenwich Mean Time");
XCTAssertEqualObjects(address.timeZone.code, @"GMT");
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)0);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);
XCTAssertNotNil(address.timeZone.currentTime);

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];

NSDateComponents *components = [[NSDateComponents alloc] init];
components.year = 2025;
components.month = 1;
components.day = 21;
components.hour = 17;
components.minute = 22;
components.second = 19;

NSDate *expectedLondonDate = [calendar dateFromComponents:components];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedLondonDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"Z"], @"London time should end with Z but was: %@", currentTime);

[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30
handler:^(NSError *_Nullable error) {
if (error) {
XCTFail();
}
}];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)test_Radar_reverseGeocode_darwin_timezone {
self.apiHelperMock.mockStatus = RadarStatusSuccess;
self.apiHelperMock.mockResponse = [RadarTestUtils jsonDictionaryFromResource:@"geocode_darwin"];

CLLocation *location = [[CLLocation alloc] initWithLatitude:-12.463872 longitude:130.844064];

XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];

[Radar reverseGeocodeLocation:location
completionHandler:^(RadarStatus status, NSArray<RadarAddress *> *_Nullable addresses) {
XCTAssertEqual(status, RadarStatusSuccess);
RadarAddress *address = addresses.firstObject;
XCTAssertNotNil(address.timeZone);
XCTAssertEqualObjects(address.timeZone._id, @"Australia/Darwin");
XCTAssertEqualObjects(address.timeZone.name, @"Australian Central Standard Time");
XCTAssertEqualObjects(address.timeZone.code, @"ACST");
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)34200);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
NSDateComponents *darwinComponents = [[NSDateComponents alloc] init];
darwinComponents.year = 2025;
darwinComponents.month = 1;
darwinComponents.day = 21;
darwinComponents.hour = 18;
darwinComponents.minute = 47;
darwinComponents.second = 35;
NSDate *expectedDarwinDate = [calendar dateFromComponents:darwinComponents];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedDarwinDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"+09:30"], @"Darwin time should end with +09:30 but was: %@", currentTime);

[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)test_Radar_ipGeocode_error {
Expand Down
10 changes: 9 additions & 1 deletion RadarSDKTests/Resources/geocode.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
"neighborhood": "DUMBO",
"number": "20",
"confidence": "exact",
"addressLabel": "20 Jay Street"
"addressLabel": "20 Jay Street",
"timeZone": {
"id": "America/New_York",
"name": "Eastern Standard Time",
"code": "EST",
"currentTime": "2025-01-21T12:19:23-05:00",
"utcOffset": -18000,
"dstOffset": 0
}
}
]
}
41 changes: 41 additions & 0 deletions RadarSDKTests/Resources/geocode_darwin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"meta": {
"code": 200
},
"addresses": [
{
"formattedAddress": "5 Cavenagh Street, Darwin CBD, NT, 0800, AU",
"addressLabel": "5 Cavenagh Street",
"number": "5",
"street": "Cavenagh Street",
"dependentLocality": "Darwin CBD",
"city": "Darwin",
"county": "Darwin",
"state": "Northern Territory",
"stateCode": "NT",
"postalCode": "0800",
"countryCode": "AU",
"country": "Australia",
"layer": "address",
"latitude": -12.463872,
"longitude": 130.844064,
"geometry": {
"type": "Point",
"coordinates": [
130.844064,
-12.463872
]
},
"distance": 41.20331642776327,
"countryFlag": "🇦🇺",
"timeZone": {
"id": "Australia/Darwin",
"name": "Australian Central Standard Time",
"code": "ACST",
"currentTime": "2025-01-22T04:17:35+09:30",
"utcOffset": 34200,
"dstOffset": 0
}
}
]
}
Loading