Watchkit扩展无法从iCloud读取 [英] Watchkit Extension Cannot Read from iCloud

查看:92
本文介绍了Watchkit扩展无法从iCloud读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找watchkit扩展以从iCloud文档存储中读取文件.我从iOS应用程序编写了文件,该应用程序也可以读取它.我利用共享类,因此代码是相同的.问题是在手表上,云容器的URL返回nil.

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
    }

在上述情况下,手表上的cloudURL为零,而手机上的为零.对于forUbiquityContainerIdentifier,我检查了手表和手机是否使用了相同的标识符.我还尝试过直接输入名称,而不是使用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

据我了解,Watch OS 3应该能够使用iCloud.

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

更新:

我打印出let token = fileManager.ubiquityIdentityToken并且得到以下信息:

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

WatchKit扩展程序[390:687462] [默认]在获取时出现[ERROR]错误 ubiquityIdentityToken:错误域= NSCocoaErrorDomain代码= 4099 与名为com.apple.bird.token的服务的连接已无效." UserInfo = {NSDebugDescription =与服务的连接名为 com.apple.bird.token无效.}

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

推荐答案

我已经从Apple正式得知,Watch OS不支持此功能.这与他们让我知道的他们自己的文档背道而驰.希望其他人能看到这种反应,并且可以节省大量我浪费的时间.

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.

这篇关于Watchkit扩展无法从iCloud读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆