Skip to content

Offline ramp up #404

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

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
27fc369
implement client side ramp up
KennyHuRadar Oct 16, 2024
9206728
fix parsing of geofences
KennyHuRadar Oct 16, 2024
e2efd53
use swift 5.0
KennyHuRadar Oct 16, 2024
429b4ed
change build definition of radar test to remove un-needed source files
KennyHuRadar Oct 17, 2024
1a38ecd
remove un-needed logging, just flacky tests
KennyHuRadar Oct 17, 2024
e84a9f0
remove logging
KennyHuRadar Oct 17, 2024
61f6b8e
update pod file
KennyHuRadar Oct 17, 2024
eb7e5d8
remove un-needed imports
KennyHuRadar Oct 17, 2024
decb2a8
update normal trackonce behaviour
KennyHuRadar Oct 17, 2024
6e54e28
clean up
KennyHuRadar Oct 17, 2024
e6e3c6a
add new swift definitions
KennyHuRadar Oct 17, 2024
65b9250
add logger to be accessible by swift
KennyHuRadar Oct 17, 2024
9142abf
add flag
KennyHuRadar Oct 17, 2024
3397fc6
put feature behind flag
KennyHuRadar Oct 17, 2024
c4e115b
bump beta version
KennyHuRadar Oct 21, 2024
e8522f3
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Oct 21, 2024
d404d57
bump to right beta version
KennyHuRadar Oct 21, 2024
3fd5b00
Update RadarSettings.m
KennyHuRadar Oct 21, 2024
c2fb45d
add build settings and suppress testing on builds for now
KennyHuRadar Oct 21, 2024
4015e47
add flag to project
KennyHuRadar Oct 21, 2024
c4828b8
uncomment out the tests
KennyHuRadar Oct 21, 2024
a87cea2
clean up
KennyHuRadar Oct 21, 2024
28ce949
remove duplicate soruce and also add some logging to adding nearby ge…
KennyHuRadar Oct 21, 2024
be8c1d2
add back compile source
KennyHuRadar Oct 21, 2024
bdfcc07
add inside geofence log message for radar offline manager
KennyHuRadar Oct 21, 2024
5ac6d23
use ramp up specific json resource and improve logging in radar state
KennyHuRadar Oct 22, 2024
c5572b3
make compatible with replays
KennyHuRadar Oct 24, 2024
b6dc7fa
only call when replay is unsuccessful
KennyHuRadar Oct 24, 2024
9b4f71d
change json file for test
KennyHuRadar Oct 24, 2024
af9e4f7
change how geofenes are turned to jsons
KennyHuRadar Oct 24, 2024
f9f874c
change shape of alternative tracking options
KennyHuRadar Oct 25, 2024
aa12fd4
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Oct 28, 2024
39af20d
refactor geofenceTag and tracking option extraction logic
KennyHuRadar Oct 28, 2024
25d1094
disable user script in build setting in radarSDKMotion
KennyHuRadar Oct 28, 2024
6dd7481
use xcode 16 in circle ci
KennyHuRadar Oct 28, 2024
4f277fd
use iphone 16 in ci
KennyHuRadar Oct 28, 2024
7f8c280
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Oct 28, 2024
25e455d
Update RadarSDKMotion.podspec
KennyHuRadar Oct 28, 2024
fc75f16
define cocoapods version (#410)
KennyHuRadar Oct 29, 2024
f2baf95
rename
KennyHuRadar Oct 29, 2024
3785164
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Oct 29, 2024
85e1abe
rename
KennyHuRadar Oct 29, 2024
761ef37
refactor updateTrackingFromConfig
KennyHuRadar Oct 30, 2024
b1cae04
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Oct 30, 2024
880cbe7
rename and fix typo
KennyHuRadar Oct 30, 2024
b6f811b
increase number of geofences synced
KennyHuRadar Nov 5, 2024
999b459
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Nov 11, 2024
41c7a36
Merge
lmeier Dec 30, 2024
ac5011e
3.19.7-beta.1
lmeier Dec 30, 2024
4769e5e
Fix merge
lmeier Dec 30, 2024
af1a7bd
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Mar 31, 2025
8681189
fix xcode merge issue
KennyHuRadar Mar 31, 2025
24b4d9e
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar Apr 14, 2025
c5c7725
Merge branch 'master' into kenny/off-line-ramp-up
KennyHuRadar May 28, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/release-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
run: xcodebuild clean build analyze test -workspace Example/Example.xcodeproj/project.xcworkspace -scheme RadarSDK -destination "platform=iOS Simulator,name=iPhone 15 Pro" | xcpretty

- name: Build archive for iPhone simulator (RadarSDK)
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphonesimulator.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphonesimulator.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

- name: Build archive for iPhone device (RadarSDK)
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphoneos.xcarchive" -sdk iphoneos SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphoneos.xcarchive" -sdk iphoneos SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

- name: Build archive for iPhone simulator (RadarSDKMotion)
run: cd RadarSDKMotion && xcodebuild archive -scheme RadarSDKMotion -archivePath "../RadarSDKMotion-iphonesimulator.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
Expand Down
3 changes: 2 additions & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Pod::Spec.new do |s|
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
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.source_files = ["RadarSDK/*.{h,m,swift}", "RadarSDK/Internal/*.{h,m}", "RadarSDK/Include/*.h"]
s.module_name = 'RadarSDK'
s.ios.deployment_target = '12.0'
s.frameworks = 'CoreLocation'
s.requires_arc = true
s.license = { :type => 'Apache-2.0' }
s.resource_bundles = {'RadarSDK' => ['RadarSDK/PrivacyInfo.xcprivacy']}
s.swift_version = '5.0'
end
73 changes: 55 additions & 18 deletions RadarSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions RadarSDK/Include/RadarTrackingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ typedef NS_ENUM(NSInteger, RadarTrackingOptionsSyncLocations) {
+ (NSString *)stringForSyncLocations:(RadarTrackingOptionsSyncLocations)syncLocations;
+ (RadarTrackingOptionsSyncLocations)syncLocationsForString:(NSString *)str;
+ (RadarTrackingOptions *_Nullable)trackingOptionsFromDictionary:(NSDictionary *_Nonnull)dictionary;
+ (RadarTrackingOptions *_Nullable)trackingOptionsFromObject:(NSObject *_Nonnull)object;
- (NSDictionary *)dictionaryValue;

@end
Expand Down
41 changes: 18 additions & 23 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ + (void)initializeWithPublishableKey:(NSString *)publishableKey options:(RadarIn
verified:NO
completionHandler:^(RadarStatus status, RadarConfig *config) {
if (status == RadarStatusSuccess && config) {
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[[RadarLocationManager sharedInstance] updateTrackingFromConfig:config];
[RadarSettings setSdkConfiguration:config.meta.sdkConfiguration];
}

Expand Down Expand Up @@ -214,20 +214,17 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
if (status == RadarStatusSuccess) {
[[RadarLocationManager sharedInstance] replaceSyncedGeofences:nearbyGeofences];
if (config != nil) {
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
}

}
[[RadarLocationManager sharedInstance] updateTrackingFromConfig:config];
if (status == RadarStatusSuccess) {
[[RadarLocationManager sharedInstance] replaceSyncedGeofences:nearbyGeofences];
}

if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
}];
}
}];
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
}];
}
}];
};

if (beacons) {
Expand Down Expand Up @@ -287,15 +284,13 @@ + (void)trackOnceWithLocation:(CLLocation *)location completionHandler:(RadarTra
beacons:nil
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
if (status == RadarStatusSuccess && config != nil) {
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[[RadarLocationManager sharedInstance] updateTrackingFromConfig:config];
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
}];
}
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
}];
}
}];
}];
}

+ (void)trackVerifiedWithCompletionHandler:(RadarTrackVerifiedCompletionHandler)completionHandler {
Expand Down Expand Up @@ -1346,7 +1341,7 @@ - (void)applicationWillEnterForeground {
if (status != RadarStatusSuccess || !config) {
return;
}
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[[RadarLocationManager sharedInstance] updateTrackingFromConfig:config];
[RadarSettings setSdkConfiguration:config.meta.sdkConfiguration];
}];
}
Expand Down
23 changes: 19 additions & 4 deletions RadarSDK/RadarAPIClient.m
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if there's a network error and replay: all is on, we should change the log level of a network error from error to info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how deeply do we want to couple these offline server fallback behaviors with the idea of replay? Asking this as I'm already creating new flags.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#import "RadarVerifiedLocationToken+Internal.h"
#import "RadarNotificationHelper.h"
#import <os/log.h>
#import "RadarOfflineManager.h"

@implementation RadarAPIClient

Expand Down Expand Up @@ -227,6 +228,7 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
params[@"anonymous"] = @(anonymous);
if (anonymous) {
params[@"deviceId"] = @"anonymous";
// this can be updated by offline event detection, which feels correct, not going to address right now for simplicity
params[@"geofenceIds"] = [RadarState geofenceIds];
params[@"placeId"] = [RadarState placeId];
params[@"regionIds"] = [RadarState regionIds];
Expand Down Expand Up @@ -313,6 +315,9 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
RadarTrackingOptions *options = [Radar getTrackingOptions];
if (options.syncGeofences) {
params[@"nearbyGeofences"] = @(YES);
if (sdkConfiguration.useOfflineRTOUpdates) {
params[@"nearbyGeofencesLimit"] = @(100);
}
}
if (beacons) {
params[@"beacons"] = [RadarBeacon arrayForBeacons:beacons];
Expand Down Expand Up @@ -465,13 +470,17 @@ - (void)makeTrackRequestWithParams:(NSDictionary *)params
if (status != RadarStatusSuccess) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Failed to flush replays"]];
[[RadarDelegateHolder sharedInstance] didFailWithStatus:status];
if ([RadarSettings sdkConfiguration].useOfflineRTOUpdates) {
return [RadarOfflineManager updateTrackingOptionsFromOfflineLocation:location completionHandler:^(RadarConfig * _Nullable config) {
return completionHandler(status, nil, nil, nil, nil, config, nil);
}];
}
} else {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug message:[NSString stringWithFormat:@"Successfully flushed replays"]];
[RadarState setLastFailedStoppedLocation:nil];
[RadarSettings updateLastTrackedTime];
}

completionHandler(status, nil, nil, nil, nil, nil, nil);
return completionHandler(status, nil, nil, nil, nil, nil, nil);
}];
} else {
[self.apiHelper requestWithMethod:@"POST"
Expand All @@ -497,10 +506,16 @@ - (void)makeTrackRequestWithParams:(NSDictionary *)params
}

[[RadarDelegateHolder sharedInstance] didFailWithStatus:status];
if ([RadarSettings sdkConfiguration].useOfflineRTOUpdates) {
return [RadarOfflineManager updateTrackingOptionsFromOfflineLocation:location completionHandler:^(RadarConfig * _Nullable config) {
return completionHandler(status, nil, nil, nil, nil, config, nil);
}];
} else {
return completionHandler(status, nil, nil, nil, nil, nil, nil);
}


return completionHandler(status, nil, nil, nil, nil, nil, nil);
}

[[RadarReplayBuffer sharedInstance] clearBuffer];
[RadarState setLastFailedStoppedLocation:nil];
[Radar flushLogs];
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarGeofence.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ - (instancetype _Nullable)initWithObject:(id)object {
radius = [((NSNumber *)radiusObj) floatValue];
}

if ([type isEqualToString:@"circle"]) {
if ([type isEqualToString:@"circle"] || [type isEqualToString:@"Circle"]) {
geometry = [[RadarCircleGeometry alloc] initWithCenter:center radius:radius];
} else if ([type isEqualToString:@"polygon"] || [type isEqualToString:@"Polygon"] || [type isEqualToString:@"isochrone"]) {
NSMutableArray<RadarCoordinate *> *mutablePolygonCoordinates = [self getPolygonCoordinates:dict];
Expand Down
3 changes: 2 additions & 1 deletion RadarSDK/RadarLocationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "Radar.h"
#import "RadarDelegate.h"
#import "RadarMeta.h"
#import "RadarConfig.h"
#import "RadarPermissionsHelper.h"
#import "RadarActivityManager.h"

Expand All @@ -32,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)replaceSyncedBeacons:(NSArray<RadarBeacon *> *)beacons;
- (void)replaceSyncedBeaconUUIDs:(NSArray<NSString *> *)uuids;
- (void)updateTracking;
- (void)updateTrackingFromMeta:(RadarMeta *_Nullable)meta;
- (void)updateTrackingFromConfig:(RadarConfig *_Nullable)config;
- (void)updateTrackingFromInitialize;

/**
Expand Down
48 changes: 30 additions & 18 deletions RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,15 @@ - (void)updateTracking:(CLLocation *)location fromInitialize:(BOOL)fromInitializ
});
}

- (void)updateTrackingFromMeta:(RadarMeta *_Nullable)meta {
if (meta) {
if ([meta trackingOptions]) {
- (void)updateTrackingFromConfig:(RadarConfig *_Nullable)config {
if (config == nil) {
return;
}
if (config.meta) {
if ([config.meta trackingOptions]) {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug
message:[NSString stringWithFormat:@"Setting remote tracking options | trackingOptions = %@", meta.trackingOptions]];
[RadarSettings setRemoteTrackingOptions:[meta trackingOptions]];
message:[NSString stringWithFormat:@"Setting remote tracking options | trackingOptions = %@", config.meta.trackingOptions]];
[RadarSettings setRemoteTrackingOptions:[config.meta trackingOptions]];
} else {
[RadarSettings removeRemoteTrackingOptions];
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug
Expand Down Expand Up @@ -523,10 +526,11 @@ - (void)replaceSyncedGeofences:(NSArray<RadarGeofence *> *)geofences {
return;
}

[RadarState setNearbyGeofences:geofences];
[self removeSyncedGeofences];

RadarTrackingOptions *options = [Radar getTrackingOptions];
NSUInteger numGeofences = MIN(geofences.count, options.beacons ? 9 : 19);
NSUInteger numGeofences = MIN(MIN(geofences.count,19), options.beacons ? 9 : 19);
NSMutableArray *requests = [NSMutableArray array];

for (int i = 0; i < numGeofences; i++) {
Expand Down Expand Up @@ -580,10 +584,11 @@ - (void)replaceSyncedGeofences:(NSArray<RadarGeofence *> *)geofences {
}
}
}

[RadarNotificationHelper removePendingNotificationsWithCompletionHandler: ^{
[RadarNotificationHelper addOnPremiseNotificationRequests:requests];
}];
if (NSClassFromString(@"XCTestCase") == nil) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is now ran in our test suite, so we need to suppress this chunk in tests as test env does not have a notification manager.

[RadarNotificationHelper removePendingNotificationsWithCompletionHandler: ^{
[RadarNotificationHelper addOnPremiseNotificationRequests:requests];
}];
}
}

- (void)removeSyncedGeofences {
Expand Down Expand Up @@ -884,8 +889,13 @@ - (void)sendLocation:(CLLocation *)location stopped:(BOOL)stopped source:(RadarL
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
self.sending = NO;

[self updateTrackingFromMeta:config.meta];

[self updateTrackingFromConfig:config];

if (status != RadarStatusSuccess || !config) {
return;
}

[self replaceSyncedGeofences:nearbyGeofences];
}];
};
Expand Down Expand Up @@ -965,13 +975,15 @@ - (void)sendLocation:(CLLocation *)location stopped:(BOOL)stopped source:(RadarL
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
self.sending = NO;
if (status != RadarStatusSuccess || !config) {
return;
}
self.sending = NO;

[self updateTrackingFromConfig:config];

if (status != RadarStatusSuccess || !config) {
return;
}

[self updateTrackingFromMeta:config.meta];
[self replaceSyncedGeofences:nearbyGeofences];
[self replaceSyncedGeofences:nearbyGeofences];
}];
}
}
Expand Down
4 changes: 2 additions & 2 deletions RadarSDK/RadarLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, nonatomic) NSDateFormatter *dateFormatter;
@property (strong, nonatomic) UIDevice *device;

+ (instancetype)sharedInstance;
- (void)logWithLevel:(RadarLogLevel)level message:(NSString *)message;
+ (instancetype)sharedInstance NS_SWIFT_NAME(sharedInstance());
- (void)logWithLevel:(RadarLogLevel)level message:(NSString *)message NS_SWIFT_NAME(log(level:message:));
- (void)logWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)message;
- (void)logWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)message includeDate:(BOOL)includeDate includeBattery:(BOOL)includeBattery;
- (void)logWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)message includeDate:(BOOL)includeDate includeBattery:(BOOL)includeBattery append:(BOOL)append;
Expand Down
20 changes: 20 additions & 0 deletions RadarSDK/RadarOfflineManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Header.h
// RadarSDK
//
// Created by Kenny Hu on 10/16/24.
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "RadarConfig.h"

NS_ASSUME_NONNULL_BEGIN

@interface RadarOfflineManager : NSObject

+ (void)updateTrackingOptionsFromOfflineLocation:(CLLocation *)location completionHandler:(void (^)(RadarConfig *))completionHandler;

@end

NS_ASSUME_NONNULL_END
Loading