FileManager.default.ubiquityIdentityToken always return nil in my tvOS app.
I found confusing information about it.
In Technical Q&A QA1935:
https://developer.apple.com/library/content/qa/qa1935/_index.html
The document say that on watchOS and tvOS, iCloud Drive is unavailable, ubiquityIdentityToken hence always returns nil for watchOS 2 WatchKit extensions and tvOS apps.
Error message generated when ubiquityIdentityToken is first-time accessed on watchOS or tvOS.
[ERROR] error while getting ubiquityIdentityToken: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.bird.token was invalidated." UserInfo={NSDebugDescription=The connection to service named com.apple.bird.token was invalidated.}
But in Xcode, I can see for ubiquityIdentityToken.
Availability:
iOS (6.0 and later), macOS (10.8 and later), tvOS (6.0 and later), watchOS (2.0 and later)
And in API Reference:
https://developer.apple.com/reference/foundation/filemanager/1408036-ubiquityidentitytoken
I can see for ubiquityIdentityToken available SDKs:
iOS 6.0+
macOS 10.8+
tvOS 9.0+
watchOS 2.0+
This might be late for you, but may be helpful for someone else.
You're supposed to use
CKContainer.fetchUserRecordID(completionHandler:)to get the user's record which is attached to the Container. The CKContainer docs talk about this a bit.
"User records provide a way to differentiate one user of the app from another through the use of a unique identifier."
So you could store this and look for any changes in the value held here - whenever you get the CKAccountChanged notification through for example.