Matter TV Casting Darwin (iOS/macOS) App Example#
This is a Matter TV Casting app for iOS and macOS that can be used to cast content to a TV. This app discovers TVs on the local network that act as commissioners, lets the user select one, sends the TV a User Directed Commissioning request, enters commissioning mode, advertises itself as a Commissionable Node and gets commissioned. Then it allows the user to send Matter commands to the TV.
Refer to the Matter Casting APIs documentation to build the Matter “Casting Client” into your consumer-facing mobile app.
Requirements#
Xcode 15.0 or later
macOS with Apple Silicon or Intel processor
iOS Simulator or physical iOS device for testing
Building the App#
Using Xcode#
Open the workspace:
cd examples/tv-casting-app/darwin open TvCastingDarwin.xcworkspace
Select the appropriate scheme:
TvCasting- Main iOS appMatterTvCastingBridge- Framework/library
Select your target device (simulator or physical device)
Build and run:
Cmd+R
Using Command Line#
Build the framework:
cd examples/tv-casting-app/darwin
xcodebuild -workspace TvCastingDarwin.xcworkspace \
-scheme MatterTvCastingBridge \
-destination 'platform=iOS Simulator,name=iPhone 16' \
build
Running Unit Tests#
The Darwin TV Casting app includes unit tests for the SendUDC functionality and other features.
Prerequisites#
The test files have been created but require one-time setup in Xcode to add them to the project:
Open the project in Xcode:
cd examples/tv-casting-app/darwin open MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj
Add a test target (if not already present):
File → New → Target
Choose “Unit Testing Bundle” under iOS
Name it
MatterTvCastingBridgeTestsSet the target to be tested to
MatterTvCastingBridgeClick Finish
Add the test file to the test target:
In the Project Navigator, right-click on
MatterTvCastingBridgeTestsfolderChoose “Add Files to MatterTvCastingBridge…”
Navigate to
MatterTvCastingBridgeTests/MCCastingPlayerSendUDCTests.mEnsure it’s added to the
MatterTvCastingBridgeTeststargetClick Add
Add OCMock dependency:
Select the project in Project Navigator
Select the
MatterTvCastingBridgeTeststargetGo to “Build Phases” → “Link Binary With Libraries”
Add OCMock framework (install via CocoaPods or Swift Package Manager if needed)
Running Tests in Xcode#
Once the test target is configured:
Open the project in Xcode
Press
Cmd+Uto run all testsOr click the diamond icon next to individual test methods to run specific tests
Or use the Test Navigator (
Cmd+6) to browse and run tests
Running Tests from Command Line#
After the test target is properly configured in Xcode:
cd examples/tv-casting-app/darwin
xcodebuild test \
-project MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj \
-scheme MatterTvCastingBridge \
-destination 'platform=iOS Simulator,name=iPhone 16'
Test Coverage#
The SendUDC test suite (MCCastingPlayerSendUDCTests.m) includes 10 test cases
covering:
Basic sendUDCWithCallbacks invocation
NoPasscode flag handling for app detection
CancelPasscode flag for ending UDC sessions
InstanceName management with UUID-based identifiers
MCTargetAppInfo handling with vendor/product IDs
CommissionerDeclarationCallback registration
Complete app detection workflow simulation
Multiple target apps support
Error handling with NSError responses
Callback validation requirements
Reviewing Test Code Without Running#
If you prefer to review the test structure without setting up the test target:
cd examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridgeTests
cat MCCastingPlayerSendUDCTests.m
The test file is complete and demonstrates proper usage of the SendUDC API with OCMock for mocking dependencies.
Troubleshooting Tests#
Issue: “Scheme is not currently configured for the test action”
Solution: The test target needs to be added to the Xcode project (see Prerequisites above)
Issue: Build errors when running tests
Solution: Ensure all dependencies are properly linked and the project builds successfully before running tests
Issue: OCMock not found
Solution: Install OCMock via CocoaPods or Swift Package Manager and link it to the test target
For more details on the test implementation, see the test documentation.
Running the App#
This example Matter TV Casting Darwin app can be tested with the example Matter tv-app running on a Raspberry Pi or other supported platform.