diff --git a/tests/unittests/obj-c/ODWSemanticContextTests.mm b/tests/unittests/obj-c/ODWSemanticContextTests.mm index 143cb1896..0096dec74 100644 --- a/tests/unittests/obj-c/ODWSemanticContextTests.mm +++ b/tests/unittests/obj-c/ODWSemanticContextTests.mm @@ -22,11 +22,15 @@ virtual void SetUserId(const std::string& userId, PiiKind) override { m_userId = userId; } virtual void SetUserAdvertisingId(const std::string& userAdvertisingId) override { m_userAdvertisingId = userAdvertisingId; } virtual void SetAppExperimentETag(const std::string& eTag) override { m_eTag = eTag; } + virtual void SetOsVersion(const std::string& osVersion) override { m_osVersion = osVersion; } + virtual void SetOsBuild(const std::string& osBuild) override { m_osBuild = osBuild; } std::string m_appId {}; std::string m_userId {}; std::string m_userAdvertisingId {}; std::string m_eTag {}; + std::string m_osVersion {}; + std::string m_osBuild {}; }; @interface ODWSemanticContextTests : XCTestCase @@ -63,4 +67,18 @@ - (void)testSetETag { XCTAssertEqual(nativeContext.m_eTag, "myETag"); } +- (void)testSetOsVersion { + TestSemanticContext nativeContext; + ODWSemanticContext* context = [[ODWSemanticContext alloc] initWithISemanticContext:&nativeContext]; + [context setOsVersion:@"10.0.19041"]; + XCTAssertEqual(nativeContext.m_osVersion, "10.0.19041"); +} + +- (void)testSetOsBuild { + TestSemanticContext nativeContext; + ODWSemanticContext* context = [[ODWSemanticContext alloc] initWithISemanticContext:&nativeContext]; + [context setOsBuild:@"19041.1234"]; + XCTAssertEqual(nativeContext.m_osBuild, "19041.1234"); +} + @end diff --git a/wrappers/obj-c/ODWSemanticContext.h b/wrappers/obj-c/ODWSemanticContext.h index bd47d0917..356ae10c7 100644 --- a/wrappers/obj-c/ODWSemanticContext.h +++ b/wrappers/obj-c/ODWSemanticContext.h @@ -53,6 +53,21 @@ NS_ASSUME_NONNULL_BEGIN */ -(void) setDeviceId:(nonnull NSString*)deviceId; +/*! + @brief Set the operating system version context information of telemetry event. + @details Overrides the OS version that the SDK populates automatically (the `DeviceInfo.OsVersion` field). Note: in the CS3 schema `ext.os.ver` is populated from the OS build, not this field, so use setOsBuild: to override `ext.os.ver`. + @param osVersion A string that contains the operating system version. + */ +-(void) setOsVersion:(nonnull NSString*)osVersion; + +/*! + @brief Set the operating system build context information of telemetry event. + @details In the CS3 schema the OS version field (`ext.os.ver`) is populated from the OS build, + so set this if setOsVersion: alone does not update `ext.os.ver`. + @param osBuild A string that contains the operating system build. + */ +-(void) setOsBuild:(nonnull NSString*)osBuild; + /*! @brief Set the user time zone context information of telemetry event. @param userTimeZone user's time zone relative to UTC, in ISO 8601 time zone format diff --git a/wrappers/obj-c/ODWSemanticContext.mm b/wrappers/obj-c/ODWSemanticContext.mm index e1077b908..d942873fd 100644 --- a/wrappers/obj-c/ODWSemanticContext.mm +++ b/wrappers/obj-c/ODWSemanticContext.mm @@ -64,6 +64,18 @@ -(void) setDeviceId:(nonnull NSString*)deviceId _wrappedSemanticContext->SetDeviceId(strDeviceId); } +-(void) setOsVersion:(nonnull NSString*)osVersion +{ + std::string strOsVersion = std::string([osVersion UTF8String]); + _wrappedSemanticContext->SetOsVersion(strOsVersion); +} + +-(void) setOsBuild:(nonnull NSString*)osBuild +{ + std::string strOsBuild = std::string([osBuild UTF8String]); + _wrappedSemanticContext->SetOsBuild(strOsBuild); +} + -(void) setUserTimeZone:(nonnull NSString*)userTimeZone { std::string strUserTimeZone = std::string([userTimeZone UTF8String]); diff --git a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift index f73fac017..184d19bc4 100644 --- a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift +++ b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift @@ -66,6 +66,30 @@ public class SemanticContext { odwSemanticContext.setDeviceId(deviceID) } + /** + Set the operating system version context information of the telemetry event. + + - Note: Overrides the OS version that the SDK populates automatically (the `DeviceInfo.OsVersion` field). In the CS3 schema `ext.os.ver` is populated from the OS build, not this field — use `setOsBuild(_:)` to override `ext.os.ver`. + + - Parameters: + - osVersion: A `String` that contains the operating system version. + */ + public func setOsVersion(_ osVersion: String) { + odwSemanticContext.setOsVersion(osVersion) + } + + /** + Set the operating system build context information of the telemetry event. + + - Note: In the CS3 schema the OS version field (`ext.os.ver`) is populated from the OS build, so set this if `setOsVersion(_:)` alone does not update `ext.os.ver`. + + - Parameters: + - osBuild: A `String` that contains the operating system build. + */ + public func setOsBuild(_ osBuild: String) { + odwSemanticContext.setOsBuild(osBuild) + } + /** Set the user time zone context information of telemetry event. diff --git a/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs b/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs index 9939ec966..30ec7efc9 100644 --- a/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs +++ b/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs @@ -281,6 +281,14 @@ public interface SemanticContext [Export ("setDeviceId:")] void SetDeviceId (string deviceId); + // -(void)setOsVersion:(NSString * _Nonnull)osVersion; + [Export ("setOsVersion:")] + void SetOsVersion (string osVersion); + + // -(void)setOsBuild:(NSString * _Nonnull)osBuild; + [Export ("setOsBuild:")] + void SetOsBuild (string osBuild); + // -(void)setUserTimeZone:(NSString * _Nonnull)userTimeZone; [Export ("setUserTimeZone:")] void SetUserTimeZone (string userTimeZone);