Watchkit Extension Cannot Read from iCloud

人走茶凉 提交于 2019-12-23 03:37:06

问题


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
    }

In the case above, cloudURL is nil on the watch but not the phone. For the forUbiquityContainerIdentifier I checked that the same identifier is used for both watch and phone. I have also tried to directly enter the name rather than using nil and letting it grab it from the entitlements. The format of the container:

iCloud.com.company.app

It's my understanding that Watch OS 3 is supposed to be able to use iCloud.

Update:

I printed out let token = fileManager.ubiquityIdentityToken and I get the following:

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.}


回答1:


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.



来源:https://stackoverflow.com/questions/42037211/watchkit-extension-cannot-read-from-icloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!