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.

Hi,

This isn't well documented, but if you're having problem with the Thread Network Configuration profile, try using it on a beta release instead of a full release build. There are known issues with this particular configuration profile, but it is working correctly on our beta releases.

-Kevin Elliott, DTS CoreOS/Hardware

I've just tried installing the 17.2 Public Beta (21C5029g) on my device. I have the profile installed. The error is different than it was on the 17.1 full release build, but still things are not working. My code looks like this:

Task {
  print("creating THClient")
  let cli = THClient()  // on 17.1, this would log an XPC error and hang indefinitely, so...progress?
  print("created THClient")
  print("is preferred available: \(await cli.isPreferredAvailable())")
  do {
    let creds = try await cli.allCredentials()
    print("All creds: \(creds)")
  } catch {
    print("Error: \(error)")
  }

  do {
    try await cli.storeCredentials(forBorderAgent: borderAgentID, activeOperationalDataSet: dataset)
    print("Added creds")
  } catch {
    print("Error adding creds: \(error)")
  }

  do {
    let creds = try await cli.allCredentials()
    print("All creds: \(creds)")
  } catch {
    print("Error: \(error)")
  }
}

The logs I get are:

creating THClient
created THClient
is preferred available: false
Client: -[THClient getConnectionEntitlementValidity]_block_invoke - Error:
Error: Error Domain=ThreadCredentialsStore Code=3 "Failed to retrieve all active border router records" UserInfo={NSLocalizedDescription=Failed to retrieve all active border router records, NSUnderlyingError=0x28198aeb0 {Error Domain=NSOSStatusErrorDomain Code=0 "(null)"}}
Error adding creds: Error Domain=ThreadCredentialsStore Code=4 "Invalid parameter sent to server..." UserInfo={NSLocalizedDescription=Invalid parameter sent to server...}
Error: Error Domain=ThreadCredentialsStore Code=3 "Failed to retrieve all active border router records" UserInfo={NSLocalizedDescription=Failed to retrieve all active border router records, NSUnderlyingError=0x281980ff0 {Error Domain=NSOSStatusErrorDomain Code=0 "(null)"}}
-[THClient storeCredentialsForBorderAgent:activeOperationalDataSet:completion:]_block_invoke:660: - Response: Error Domain=ThreadCredentialsStore Code=4 "Invalid parameter sent to server..." UserInfo={NSLocalizedDescription=Invalid parameter sent to server...}

I also just tried try await cli.credentials(forBorderAgentID: borderAgentID), which immediately crashes with

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSError storeError:description:]: unrecognized selector sent to class 0x1f9f21378'

...as well as try await cli.credentials(forExtendedPANID: extendedPANID), which crashes with

:0: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

:(

(Also worth mentioning: when I call these same APIs on macOS, they seem to silently do nothing without reporting any errors, which is not much better than hanging or crashing!)

I also experience same error in iOS 17.1.1 with following message:

Client: -[THClient connectToXPCService]_block_invoke - CTCS XPC Client is invalidated.

I am experiencing the same issue here, when running on iOS 17.1.1 I get:

Client: -[THClient getConnectionEntitlementValidity]_block_invoke - Error:

And when trying to retrieve credentials:

Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=ThreadCredentialsStore Code=3 "Failed to retrieve all active border router records" UserInfo={NSLocalizedDescription=Failed to retrieve all active border router records, NSUnderlyingError=0x282c197a0 {Error Domain=NSOSStatusErrorDomain Code=0 "(null)"}}

I also tried to do the same on mac and as previous mentioned in this thread, it silently does nothing, no error but also does not succeed.

I updated to iOS 17.2, and now I can save and manage credentials. However, I ran into a problem because the ThreadNetwork profile on my device expired. I reinstall it again, but I'm getting an error saying the "ThreadNetwork Framework Support" profile is no longer valid.

Same problem here, since today I cannot use the profile anymore. Yesterday it was working fine. Using latest iOS 17.2 beta 3

I'm also trying to get access to the Thread network credentials. I've installed iOS 17.2 beta 3 and I get the same 'profile invalid' error when trying to install it.

Today I finally made it work, not sure exactly what I did, but first it started working on my iPad with beta iOS, then suddenly also on my iPhone with stable iOS.

I also think I removed and added back the ”manage thread networks” capability in the project.

QUESTION: The Only thing I wasn’t able to succeed is to store my thread network using THClient “store credentials” method, it always says I’m passing invalid parameter, so my question is how to convert my borderAgentID string into Data properly, same for the dataset string.

Anyone succeeded on that?

How do I use a Thread Network API in IOS
 
 
Q