【问题标题】:Watchkit Extension Cannot Read from iCloudWatchkit 扩展无法从 iCloud 读取
【发布时间】:2017-06-21 14:09:44
【问题描述】:

我正在寻找用于从 iCloud 文档存储中读取文件的 watchkit 扩展。我从 iOS 应用程序中编写了该文件,该应用程序也能够读取它。我正在利用一个共享类,所以代码是一样的。问题是在手表上,云容器的 URL 返回 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 在手表上是 nil 而不是手机上。对于forUbiquityContainerIdentifier,我检查了手表和手机是否使用了相同的标识符。我还尝试直接输入名称,而不是使用 nil 并让它从权利中获取它。容器的格式:

iCloud.com.company.app

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

更新:

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

WatchKit Extension[390:687462] [default] [ERROR] 获取错误 ubiquityIdentityToken: 错误域=NSCocoaErrorDomain 代码=4099" 与名为 com.apple.bird.token 的服务的连接已失效。” UserInfo={NSDebugDescription=与服务的连接名为 com.apple.bird.token 已失效。}

【问题讨论】:

    标签: swift watchkit icloud


    【解决方案1】:

    那是 2021 年。Apple 文档仍然说 iCloud Drive 方法可以被 watchOS 2.0+ 使用,但是 url forUbiquityContainerIdentifier 返回 nil :(

    【讨论】:

      【解决方案2】:

      我已正式从 Apple 获悉,这不是 Watch OS 支持的功能。这与我让他们知道的他们自己的文档背道而驰。希望其他人看到这个回复,它可以节省我浪费的大量时间。

      【讨论】:

      • 你有雷达网址吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多