I was dealing with this same issue in some older Objective-C code I was trying to update. After lots of different attempts I found the following solution (Swift version):
if let token = FileManager.default.ubiquityIdentityToken {
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: token, requiringSecureCoding: true)
if let newToken = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSData.self, from: data) {
print("We got the token")
if newToken.isEqual(token) {
print("tokens match")
} else {
print("tokens do not match")
}
}
} catch {
print("oops: ", error)
}
}
This works and it compiles cleanly. But I'm worried that passing in NSData.self could possibly fail in some future implementation if Apple changes how the token is encoded.
Topic:
App & System Services
SubTopic:
General
Tags: