MatterSupport integrated with objective-c No MatterAddDeviceExtensionRequestHandler

Run the sample code as doc https://developer.apple.com/documentation/mattersupport?changes=latest_minor

import MatterSupport

let request = MatterAddDeviceRequest(

    topology: .init(ecosystemName: "Acme SmartHome", homes: [

        .init(displayName: "Default Acme Home"),

    ])

)

do {

    try await request.perform()

    print("Successfully set up a device!")

} catch {

    print("Failed to set up a device with error: \(error)")

}

it runs but stuck in the scene below, never get the callback.

Another issue about MatterSupport, when integrated with objective-c the bridge file(eg xx-Swift.h) turn out to show error:

Cannot find interface declaration for 'MatterAddDeviceExtensionRequestHandler', superclass of 'MatterAddDeviceHandler'

Xcode Version 14.2 (14C18) My code:

//
//  MatterHelper.swift
//  xx
//
//  Created by Robin on 2023/3/21.
//

import Foundation
import MatterSupport

@available(iOS 16.1, *)
class MatterHelper: NSObject
{
    @objc class func commission()
    {
        let request = MatterAddDeviceRequest(
            topology: .init(ecosystemName: "RRRRRR", homes: [
                .init(displayName: "R11111"), .init(displayName: "R222222")
            ])
        )
        Task.init
        {
            do
            {
                try await request.perform()
                print("Successfully set up a device!")
            }
            catch
            {
                print("Failed to set up a device with error: \(error)")
            }
        }
    }
}

@available(iOS 16.1, *)
class MatterAddDeviceHandler: MatterAddDeviceExtensionRequestHandler
{
    override func validateDeviceCredential(_ deviceCredential: MatterAddDeviceExtensionRequestHandler.DeviceCredential) async throws
    {

        print("validateDeviceCredential \(deviceCredential)")
    }

   
    override func selectThreadNetwork(from threadScanResults: [MatterAddDeviceExtensionRequestHandler.ThreadScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.ThreadNetworkAssociation
    {
        print("selectThreadNetwork \(threadScanResults)")
        return ThreadNetworkAssociation.defaultSystemNetwork
    }

    
    override func commissionDevice(in home: MatterAddDeviceRequest.Home?, onboardingPayload: String, commissioningID: UUID) async throws
    {
        print("Home: \(String(describing: home)) " + "payload: \(onboardingPayload) "  + "commissionID: \(commissioningID)")
    }
}

Many thanks for your help.

Answered by RobinGao in 748641022

Found a new target Matter extension. To add a matter extension new target can resolve this.

Accepted Answer

Found a new target Matter extension. To add a matter extension new target can resolve this.

is overrides the functions but, how I can communicate with mainApp and the requesthandler Extension?

Hi there: I have same issue, I added MatterExtension and App group, but still get no trigger on commissionDevice, did I miss something here? @RobinGao

MatterSupport integrated with objective-c No MatterAddDeviceExtensionRequestHandler
 
 
Q