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
6 changes: 6 additions & 0 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,12 @@ + (void) __writeToLogBufferWithLevel:(RadarLogLevel)level type:(RadarLogType)typ
}

+ (void)requestMotionActivityPermission {
if ([RadarState promptedForMotionUsage]) {
return;
}
if ([RadarSettings delayedMotionUsage]) {
[RadarState setPromptedForMotionUsage:YES];
}
[[RadarActivityManager sharedInstance] requestPermission];
}

Expand Down
8 changes: 5 additions & 3 deletions RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
}

NSMutableDictionary *locationMetadata = [NSMutableDictionary new];
if (options.useMotion) {
BOOL useMotion = options.useMotion && ([RadarState promptedForMotionUsage] || ![RadarSettings delayedMotionUsage]);
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't this be true if requestMotionActivityPermission is never called and delayedMotionUsage is not set

BOOL usePressure = options.usePressure && ([RadarState promptedForMotionUsage] || ![RadarSettings delayedMotionUsage]);
if (useMotion) {
locationMetadata[@"motionActivityData"] = [RadarState lastMotionActivityData];
locationMetadata[@"heading"] = [RadarState lastHeadingData];
locationMetadata[@"speed"] = @(location.speed);
Expand All @@ -416,13 +418,13 @@ - (void)trackWithLocation:(CLLocation *_Nonnull)location
}
}

if (options.usePressure) {
if (usePressure) {
locationMetadata[@"altitude"] = @(location.altitude);
locationMetadata[@"floor"] = @([location.floor level]);
locationMetadata[@"pressureHPa"] = [RadarState lastRelativeAltitudeData];
}

if (options.usePressure || options.useMotion) {
if (usePressure || useMotion) {
params[@"locationMetadata"] = locationMetadata;
}

Expand Down
4 changes: 2 additions & 2 deletions RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ - (void)updateTracking:(CLLocation *)location fromInitialize:(BOOL)fromInitializ



if (options.useMotion) {
if (options.useMotion && ([RadarState promptedForMotionUsage] || ![RadarSettings delayedMotionUsage])) {
self.activityManager = [RadarActivityManager sharedInstance];
self.locationManager.headingFilter = 5;
[self.locationManager startUpdatingHeading];
Expand Down Expand Up @@ -391,7 +391,7 @@ - (void)updateTracking:(CLLocation *)location fromInitialize:(BOOL)fromInitializ
}];

}
if (options.usePressure) {
if (options.usePressure && ([RadarState promptedForMotionUsage] || ![RadarSettings delayedMotionUsage])) {
self.activityManager = [RadarActivityManager sharedInstance];

[self.activityManager startRelativeAltitudeWithHandler: ^(CMAltitudeData * _Nullable altitudeData) {
Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/RadarSdkConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, assign) BOOL syncAfterSetUser;

@property (nonatomic, assign) BOOL delayedMotionUsage;

/**
Initializes a new RadarSdkConfiguration object with given value.
*/
Expand Down
8 changes: 7 additions & 1 deletion RadarSDK/RadarSdkConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
_useForegroundLocationUpdatedAtMsDiff = NO;
_useNotificationDiff = NO;
_syncAfterSetUser = NO;
_delayedMotionUsage = NO;
Copy link
Contributor

Choose a reason for hiding this comment

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

why an sdk config instead of a initialize option?

Copy link
Contributor

Choose a reason for hiding this comment

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

if the sdk config request fails, could that trigger the motion prompt?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh because useMotion is a SDK config?


if (dict == nil) {
return self;
Expand Down Expand Up @@ -93,6 +94,11 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
_syncAfterSetUser = [(NSNumber *)syncAfterSetUserObj boolValue];
}

NSObject *delayedMotionUsageObj = dict[@"delayedMotionUsage"];
if (delayedMotionUsageObj && [delayedMotionUsageObj isKindOfClass:[NSNumber class]]) {
_delayedMotionUsage = [(NSNumber *)delayedMotionUsageObj boolValue];
}

return self;
}

Expand All @@ -110,7 +116,7 @@ - (NSDictionary *)dictionaryValue {
dict[@"useForegroundLocationUpdatedAtMsDiff"] = @(_useForegroundLocationUpdatedAtMsDiff);
dict[@"useNotificationDiff"] = @(_useNotificationDiff);
dict[@"syncAfterSetUser"] = @(_syncAfterSetUser);

dict[@"delayedMotionUsage"] = @(_delayedMotionUsage);
return dict;
}

Expand Down
1 change: 1 addition & 0 deletions RadarSDK/RadarSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)updateLastAppOpenTime;
+ (NSDate *)lastAppOpenTime;
+ (BOOL)useRadarModifiedBeacon;
+ (BOOL)delayedMotionUsage;
+ (BOOL)xPlatform;
+ (NSString *)xPlatformSDKType;
+ (NSString *)xPlatformSDKVersion;
Expand Down
4 changes: 4 additions & 0 deletions RadarSDK/RadarSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ + (BOOL)useRadarModifiedBeacon {
return [[self sdkConfiguration] useRadarModifiedBeacon];
}

+ (BOOL)delayedMotionUsage {
return [[self sdkConfiguration] delayedMotionUsage];
}

+ (BOOL)xPlatform {
return [[NSUserDefaults standardUserDefaults] stringForKey:kXPlatformSDKType] != nil &&
[[NSUserDefaults standardUserDefaults] stringForKey:kXPlatformSDKVersion];
Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/RadarState.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)addRegisteredNotification:(NSDictionary *)registeredNotification;
+ (NSDictionary *)lastRelativeAltitudeData;
+ (void)setLastRelativeAltitudeData:(NSDictionary *_Nullable)lastRelativeAltitudeData;
+ (void)setPromptedForMotionUsage:(BOOL)promptedForMotionUsage;
+ (BOOL)promptedForMotionUsage;

@end

Expand Down
9 changes: 9 additions & 0 deletions RadarSDK/RadarState.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ @implementation RadarState
static NSString *const kLastPressureData = @"radar-lastPressureData";
static NSString *const kNotificationPermissionGranted = @"radar-notificationPermissionGranted";
static NSString *const kRegisteredNotifications = @"radar-registeredNotifications";
static NSString *const kPromptedForMotionUsage = @"radar-promptedForMotionUsage";
static NSDictionary *_lastRelativeAltitudeDataInMemory = nil;
static NSDate *_lastPressureBackupTime = nil;
static NSTimeInterval const kBackupInterval = 2.0; // 2 seconds
Expand Down Expand Up @@ -249,4 +250,12 @@ + (void)addRegisteredNotification:(NSDictionary *)notification {
[RadarState setRegisteredNotifications:registeredNotifications];
}

+ (void)setPromptedForMotionUsage:(BOOL)promptedForMotionUsage {
[[NSUserDefaults standardUserDefaults] setBool:promptedForMotionUsage forKey:kPromptedForMotionUsage];
}

+ (BOOL)promptedForMotionUsage {
return [[NSUserDefaults standardUserDefaults] boolForKey:kPromptedForMotionUsage];
}

@end
3 changes: 2 additions & 1 deletion RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,8 @@ - (void)test_RadarSdkConfiguration {
@"extendFlushReplays": @(NO),
@"useLogPersistence": @(NO),
@"useRadarModifiedBeacon": @(NO),
@"syncAfterSetUser": @(NO)
@"syncAfterSetUser": @(NO),
@"delayedMotionUsage": @(YES),
}];

[RadarSettings setSdkConfiguration:sdkConfiguration];
Expand Down