I am looking for the watchkit extension to read a file from iCloud document storage. I wrote the file from the iOS app which is also able to read it. I am leveraging a shared class so the code is the same. The problem is that on the watch, the URL for the cloud container returns nil.
static func readFromFile(fileName:String) -> String?
{
let fileManager = FileManager.default
var cloudURL = fileManager.url(forUbiquityContainerIdentifier: nil)
cloudURL = cloudURL?.appendingPathComponent("Documents/\(fileName)")
do
{
return try String(contentsOf: cloudURL!)
} catch {
print (error)
return nil
}
forUbiquityContainerIdentifier
iCloud.com.company.app
let token = fileManager.ubiquityIdentityToken
WatchKit Extension[390:687462] [default] [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.}
I have officially heard back from Apple that this is not a supported feature of Watch OS. This runs contrary to their own documentation which I let them know about. Hopefully others see this response and it can save a ton of time that I wound up wasting.