Thank you for your answer.
I followed your idea to store the THClient reference as a member variable of the object instead of a local reference, but this led me to the same error.
I found this post:
https://developer.apple.com/forums/thread/718467?answerId=768704022#768704022
and followed the idea, to make a "softlink" in the callback to the objects thclient reference and this works. So yes, the objects ref is somehow removed by garbage collection.
Working example:
import ThreadNetwork
import OSLog
@available(iOS 15.0, *)
public class ThreadManager {
let client = THClient()
func storeThread() {
guard let baIdData = Data(hexString: "<baId>") else { return }
guard let tlvData = Data(hexString: "<tlv>") else { return }
os_log(.default, "THREAD SETUP")
self.client.storeCredentials(forBorderAgent: baIdData, activeOperationalDataSet: tlvData) { error in
let c = self.client // the magic, setting a "softlink" will work
if let error = error {
os_log(.error, "thread error \(error)")
} else {
os_log(.debug, "thread creds stored")
}
}
}
}
Topic:
App & System Services
SubTopic:
Networking
Tags: