Expose setOsVersion/setOsBuild on Obj-C ODWSemanticContext (resolves #1093)#1482
Expose setOsVersion/setOsBuild on Obj-C ODWSemanticContext (resolves #1093)#1482bmehta001 wants to merge 3 commits into
Conversation
The Obj-C/iOS wrapper exposed app/user/device context setters but no way to override the OS version, so iOS clients could not set DeviceInfo.OsVersion (Common Schema `ext.os.ver`) themselves -- the gap reported in microsoft#1093. The C++ core already provides ISemanticContext::SetOsVersion/SetOsBuild; this wires them through the wrapper. - ODWSemanticContext.h/.mm: add setOsVersion: and setOsBuild:, forwarding to the wrapped ISemanticContext (mirrors the existing setDeviceId pattern). - ODWSemanticContextTests.mm: add testSetOsVersion and testSetOsBuild, with the test mock capturing SetOsVersion/SetOsBuild. Note: per the microsoft#1093 discussion, in the CS3 schema `ext.os.ver` is populated from the OS build (COMMONFIELDS_OS_BUILD), so both setters are exposed. Resolves microsoft#1093. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Validation status for this change: iOS/macOS CI compiled the Obj-C wrapper successfully. The macOS/iOS C++ core API compile-checked locally (WSL, g++ -std=c++11): a mock The forwarding mirrors the existing
|
There was a problem hiding this comment.
Pull request overview
This PR exposes setOsVersion: and setOsBuild: on the Obj-C ODWSemanticContext wrapper so Obj-C/iOS clients can override OS version/build semantic context values that the C++ core already supports, addressing the API gap described in #1093.
Changes:
- Add Obj-C wrapper methods
setOsVersion:/setOsBuild:that forward toISemanticContext::SetOsVersion/SetOsBuild. - Add Obj-C unit tests covering the new setters and extend the test mock to capture the values.
- Update Obj-C header documentation for the new APIs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| wrappers/obj-c/ODWSemanticContext.mm | Adds forwarding implementations for setOsVersion: and setOsBuild:. |
| wrappers/obj-c/ODWSemanticContext.h | Adds public Obj-C API declarations and documentation for the new setters. |
| tests/unittests/obj-c/ODWSemanticContextTests.mm | Adds unit tests and mock capture fields for OS version/build setters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::string strOsVersion = std::string([osVersion UTF8String]); | ||
| _wrappedSemanticContext->SetOsVersion(strOsVersion); |
There was a problem hiding this comment.
These two setters intentionally follow the established idiom used by every other setter in ODWSemanticContext.mm (setAppLanguage:, setUserId:, setDeviceId:, etc. all do std::string([param UTF8String])), and the parameters are declared nonnull. Adding a UTF8String-null guard to only setOsVersion:/setOsBuild: would be inconsistent with the other ~10 setters. Null-hardening the NSString->std::string conversion is a reasonable improvement, but it should be a separate file-wide change (ideally a shared helper) rather than scoped to these two new setters. No change here.
| std::string strOsBuild = std::string([osBuild UTF8String]); | ||
| _wrappedSemanticContext->SetOsBuild(strOsBuild); |
There was a problem hiding this comment.
These two setters intentionally follow the established idiom used by every other setter in ODWSemanticContext.mm (setAppLanguage:, setUserId:, setDeviceId:, etc. all do std::string([param UTF8String])), and the parameters are declared nonnull. Adding a UTF8String-null guard to only setOsVersion:/setOsBuild: would be inconsistent with the other ~10 setters. Null-hardening the NSString->std::string conversion is a reasonable improvement, but it should be a separate file-wide change (ideally a shared helper) rather than scoped to these two new setters. No change here.
| @brief Set the operating system version context information of telemetry event. | ||
| @details Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). | ||
| @param osVersion A string that contains the operating system version. | ||
| */ | ||
| -(void) setOsVersion:(nonnull NSString*)osVersion; |
Code review noted that PR microsoft#1093 (an iOS request) was only addressed on the Obj-C ODWSemanticContext. The repo also ships hand-written Swift (OneDSSwift) and Xamarin iOS bindings that mirror every other ODWSemanticContext setter one-to-one, so Swift and Xamarin/iOS consumers still could not set the OS version/build. Add the two setters to both bindings, forwarding to the Obj-C selectors (setOsVersion:/setOsBuild:), placed next to the device-id setter to match the Obj-C header ordering: - wrappers/swift/Sources/OneDSSwift/SemanticContext.swift: setOsVersion(_:)/ setOsBuild(_:) -> odwSemanticContext.setOsVersion/.setOsBuild - wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs: [Export("setOsVersion:")] / [Export("setOsBuild:")] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
|
||
| /*! | ||
| @brief Set the operating system version context information of telemetry event. | ||
| @details Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). |
| /** | ||
| Set the operating system version context information of the telemetry event. | ||
|
|
||
| - Note: Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). |
…ver mapping) Code review found the setOsVersion doc comments were misleading: in the CS3 schema ext.os.ver is populated from COMMONFIELDS_OS_BUILD, not OS_VERSION (ContextFieldsProvider.cpp:259-263 sets extOs[0].ver from COMMONFIELDS_OS_BUILD; OS_VERSION is commented out). setOsVersion overrides DeviceInfo.OsVersion and does NOT update ext.os.ver -- setOsBuild does. Correct the @details/Note in ODWSemanticContext.h and the Swift wrapper to say setOsVersion overrides DeviceInfo.OsVersion and point to setOsBuild for ext.os.ver. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What
Expose
setOsVersion:andsetOsBuild:on the Obj-C wrapper'sODWSemanticContext, so iOS/Obj-C clients can override the OS version (DeviceInfo.OsVersion/ Common Schemaext.os.ver) the SDK populates automatically.Why
Per #1093, a client needed to set
DeviceInfo.OsVersionfrom app code on iOS. The C++ core already providesISemanticContext::SetOsVersion()/SetOsBuild()(ISemanticContext.hppviaDECLARE_COMMONFIELD), but the Obj-C wrapper exposed only app/user/device-id/experiment setters — no OS-version setter — so there was no way to do this from the Obj-C API. (As noted in the issue thread, in the CS3 schemaext.os.veris populated from the OS build (COMMONFIELDS_OS_BUILD), so both setters are exposed.)Changes
wrappers/obj-c/ODWSemanticContext.h/.mm— addsetOsVersion:andsetOsBuild:, each converting theNSStringtostd::stringand forwarding to the wrappedISemanticContext(SetOsVersion/SetOsBuild). Mirrors the existingsetDeviceId:pattern.tests/unittests/obj-c/ODWSemanticContextTests.mm— addtestSetOsVersionandtestSetOsBuild; the existingTestSemanticContextmock now capturesSetOsVersion/SetOsBuild.Usage
Validation
SetOsVersion/SetOsBuildare non-purevirtual void Set...(const std::string&)generated byDECLARE_COMMONFIELD(CommonFields.h), so the wrapper calls and the test-mockoverrides match the core signatures. The Obj-C wrapper builds and the XCTest run on the macOS/iOS CI — this change couldn't be compiled locally (no Obj-C toolchain on the dev box), so it relies on CI for the build/test confirmation.Resolves #1093.