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
18 changes: 18 additions & 0 deletions tests/unittests/obj-c/ODWSemanticContextTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions wrappers/obj-c/ODWSemanticContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions wrappers/obj-c/ODWSemanticContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
24 changes: 24 additions & 0 deletions wrappers/swift/Sources/OneDSSwift/SemanticContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading