swift - Watchkit 扩展无法从 iCloud 读取

标签 swift watchkit icloud

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

iCloud.com.company.app

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

更新:

我打印出 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.}

最佳答案

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

关于swift - Watchkit 扩展无法从 iCloud 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42037211/

相关文章:

ios - 可以在数组中添加一些填充吗?

ios - WatchKit选项只能听写吗?

swift - 是否可以在 WatchKit 中创建一个按钮数组?

ios - NSUserDefaults 以外的本地键值存储

android - 在 Android 设备中集成 iCloud

delegates - 通过 Swift 访问委托(delegate)的正确方法是什么?

ios - 试图使同一索引路径的多个单元格出队,这是不允许的。错误

swift - 如何在 Swift 中通过命令行读取一行?

ios - 在 WatchKit 应用程序中检测事件接口(interface) Controller ?

ios - iOS 6 上未配置 iCloud 状态