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

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?

Tip: When storing credetials make sure you are using the mac extended address as border agent ID, this was crucial to make it work for me.

How do I use a Thread Network API in IOS
 
 
Q