How do I use a Thread Network API in IOS

Hi there I tried to use a Thread Network in my App. Actually I added ThreadNetwork in frameworks folder and I tried to initialize THClient pointer. THClient* Thread = [[THClient alloc] init];

but error is occur as bellowing "[thclient] Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated."

May I get an advice?? Thanks

I tried to use a Thread Network in my App.

Were you granted access to the corresponding entitlement?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, I have the same issue,

from the documentation here, I can read:

To use the ThreadNetwork framework during development, install the ThreadNetwork mobile profile. Once you’re ready to publish your app, request permission for this entitlement from the ThreadNetwork Framework Entitlement Request page.

The documentation seems to suggest I am supposed to be able to test the framework by installing the linked profile on my test device, and only request the entitlement once I am ready to publish [my] app. After installing the ThreadNetwork mobile profile on my test device:

  • If I try to add the entitlement to the entitlement config file, XCode will fail to sign the app for development purposes, so I can't run it on my test device.
  • If I try to remove the entitlement from the entitlement config file, the app will crash with the same issue as the main post.

Did I mis-interpret the documentation, are is there a specific setup to develop and test ThreadNetwork Capabilities?

Thanks

Hello

I face exactly the same issue using XCode 14 or XCode 15 beta 3: manually adding the entitlement leads to a compilation error and there is no way to select the entitlement com.apple.developer.networking.manage-thread-network-credentials within XCode.

Any help would be greatly appreciated.

Hi,

same issue here. The ThreadNetwork mobile profile does not seem to work. Same error when trying to create a THClient:[THClient] Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated.

@eskimo any news about this issue?

A bit more information from the console logging:

error	13:28:37.700602+0200	kernel	1 duplicate report for Sandbox: HomeyApp(468) deny(1) sysctl-read kern.bootargs
error	13:28:37.700647+0200	kernel	Sandbox: HomeyApp(468) deny(1) mach-lookup com.apple.ThreadNetwork.xpc
default	13:28:37.700732+0200	HomeyApp	[0x2828b5100] activating connection: mach=true listener=false peer=false name=com.apple.ThreadNetwork.xpc
default	13:28:37.700943+0200	HomeyApp	[0x2828b5100] failed to do a bootstrap look-up: xpc_error=[159: Unknown error: 159]
default	13:28:37.701052+0200	HomeyApp	[0x2828b5100] invalidated after a failed init
error	13:28:37.704147+0200	HomeyApp	Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated.

This is on iOS 17 (21A5291h)

Same issue here... it's gonna be difficult to get this multi-vendor network standard off the ground if we can't even use the APIs!

has anyone found a solution ?

same issue here

Same issue as @TeunVRAthom. I installed the ThreadNetwork mobile profile on an iOS 17 device and I'm getting the same error whenever I'm trying to access the THClient.

It works in iOS 17.1 using asynchronous code

        let extPanIdHex = "yourExtPanId"
        
        if let extPadIdData = Data(hexString: extPanIdHex)
        {
            let thClient = THClient()
            
            Task
            {
                let credentials = try await thClient.credentials(forExtendedPANID: extPadIdData)
            }
        }

Sinchronous code still has some problems

This one doesn't work

            let thClient = THClient()

            thClient.retrieveCredentials(forExtendedPANID: extPadIdData) { credentials, error in
                NSLog("")
            }

Returned error

Client: -[THClient retrievePreferredCredentials:]_block_invoke - Error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 396 named com.apple.ThreadNetwork.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 396 named com.apple.ThreadNetwork.xpc was invalidated from this process.}

But this one oddly works

            let thClient = THClient()

            thClient.retrieveCredentials(forExtendedPANID: extPadIdData) { credentials, error in
                let c = thClient
                NSLog("")
            }

Do you have the corresponding entitlement enabled on the app? Or you just install the mobile profile on the device? I'm asking because I was never able to make it work. We don't have the corresponding entitlement yet, we only install the mobile profile on an iOS 17.1 device. I'm getting an error just by doing let thClient = THClient() in a function.

It is also working a bit better for me on iOS 17.1. Still easy to make it crash, but at least something seems to be working. I can create a THClient and store my credentials etc. This is with the test-profile. Unfortunately not much progress on the entitlement side.

I wonder what's wrong with my setup.

When calling this function provided from the docs, I'm still getting Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated error.

func obtainCredentials(borderAgentID: Data) async -> (cred: THCredentials? ,err: Error? ) {
    let client = THClient()
    var credential: THCredentials?
    var err:Error?
    do {
        credential = try await client.credentials(forBorderAgentID: borderAgentID as Data)
    } catch {
        err = error
    }
    return (credential, err)
}

@TeunVRAthom would you mind sharing what you did to make the THClient work?

In your previous reply, you were experiencing this error, "THClient:[THClient] Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated". What did you do to fix it?

Thanks!

Hi, i don't know what i did to make THClient work unfortunately because at the moment it is no longer working again :( I tried rebooting the device, reinstalling the profile etc but no success yet.

How do I use a Thread Network API in IOS
 
 
Q