Skip to content

Commit 449b164

Browse files
Merge pull request #214 from Automattic/wcios/track-accessibility-font-setting
Add iOS device accessibility settings to device properties.
2 parents ef5cc5a + bbb876a commit 449b164

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

Automattic-Tracks-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'Automattic-Tracks-iOS'
5-
s.version = '0.11.1'
5+
s.version = '0.12.0-beta.1'
66

77
s.summary = 'Simple way to track events in an iOS app with Automattic Tracks internal service'
88
s.description = <<-DESC

Sources/Event Logging/TracksService.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ @interface TracksService ()
6262
NSString *const DeviceInfoVoiceOverEnabledKey = @"device_info_voiceover_enabled";
6363
NSString *const DeviceInfoStatusBarHeightKey = @"device_info_status_bar_height";
6464
NSString *const DeviceInfoOrientation = @"device_info_orientation";
65+
NSString *const DeviceInfoPreferredContentSizeCategory = @"device_info_preferred_content_size_category";
66+
NSString *const DeviceInfoIsAccessibilityCategory = @"device_info_is_accessibility_category";
6567

6668
NSString *const TracksEventNameKey = @"_en";
6769
NSString *const TracksUserAgentKey = @"_via_ua";
@@ -398,7 +400,9 @@ - (NSDictionary *)mutableDeviceProperties
398400
DeviceInfoAppleWatchConnectedKey : self.deviceInformation.isAppleWatchConnected ? @"YES" : @"NO",
399401
DeviceInfoStatusBarHeightKey : [NSNumber numberWithFloat:self.deviceInformation.statusBarHeight],
400402
DeviceInfoOrientation : self.deviceInformation.orientation ?: @"Unknown",
401-
};
403+
DeviceInfoPreferredContentSizeCategory : self.deviceInformation.preferredContentSizeCategory ?: @"Unknown",
404+
DeviceInfoIsAccessibilityCategory : self.deviceInformation.isAccessibilityCategory ? @"YES" : @"NO",
405+
};
402406
}
403407

404408
- (NSDictionary *)dictionaryForTracksEvent:(TracksEvent *)tracksEvent withParentCommonProperties:(NSDictionary *)parentCommonProperties

Sources/Model/ObjC/Common/TracksDeviceInformation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ NS_ASSUME_NONNULL_BEGIN
2121
@property (nullable, nonatomic, readonly) NSString *currentNetworkOperator;
2222
@property (nullable, nonatomic, readonly) NSString *currentNetworkRadioType;
2323
@property (nonatomic, assign) BOOL isWiFiConnected;
24+
25+
/// Preferred reading content size based on the accessibility setting of the iOS device.
26+
/// - This will be NULL for Mac OS.
27+
///
28+
@property (nullable, nonatomic, readonly) NSString *preferredContentSizeCategory;
29+
30+
/// Returns `true` if the preferred reading content size falls under accessibility category.
31+
///
32+
/// - Uses `UIContentSizeCategoryIsAccessibilityCategory` method.
33+
/// - This will be `false` for Mac OS.
34+
///
35+
@property (nonatomic, readonly) BOOL isAccessibilityCategory;
36+
2437
/**
2538
* Indicates whether the device has an Internet connection.
2639
*/

Sources/Model/ObjC/Common/TracksDeviceInformation.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,51 @@ - (UIInterfaceOrientation)statusBarOrientation {
206206
}
207207
#endif
208208

209+
/// Preferred reading content size based on the accessibility setting of the iOS device.
210+
///
211+
/// - This will be NULL for Mac OS.
212+
///
213+
- (NSString *)preferredContentSizeCategory {
214+
#if TARGET_OS_IPHONE
215+
if ([NSThread isMainThread]) {
216+
return UIApplication.sharedIfAvailable.preferredContentSizeCategory;
217+
}
218+
219+
__block NSString *preferredContentSizeCategory;
220+
221+
dispatch_sync(dispatch_get_main_queue(), ^{
222+
preferredContentSizeCategory = UIApplication.sharedIfAvailable.preferredContentSizeCategory;
223+
});
224+
225+
return preferredContentSizeCategory;
226+
#else // Mac
227+
return NULL;
228+
#endif
229+
}
230+
231+
/// Returns `true` if the preferred reading content size falls under accessibility category.
232+
///
233+
/// - Uses `UIContentSizeCategoryIsAccessibilityCategory` method.
234+
/// - This will be `false` for Mac OS.
235+
///
236+
- (BOOL)isAccessibilityCategory {
237+
#if TARGET_OS_IPHONE
238+
__block NSString *preferredContentSizeCategory;
239+
240+
if ([NSThread isMainThread]) {
241+
preferredContentSizeCategory = UIApplication.sharedIfAvailable.preferredContentSizeCategory;
242+
} else {
243+
dispatch_sync(dispatch_get_main_queue(), ^{
244+
preferredContentSizeCategory = UIApplication.sharedIfAvailable.preferredContentSizeCategory;
245+
});
246+
}
247+
248+
return UIContentSizeCategoryIsAccessibilityCategory(preferredContentSizeCategory);
249+
#else // Mac
250+
return NO;
251+
#endif
252+
}
253+
209254
#pragma mark - App Specific Information
210255

211256
- (NSString *)appName
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#import "TracksConstants.h"
22

33
NSString *const TracksErrorDomain = @"TracksErrorDomain";
4-
NSString *const TracksLibraryVersion = @"0.11.1";
4+
NSString *const TracksLibraryVersion = @"0.12.0-beta.1";

0 commit comments

Comments
 (0)