无法在保留现有iCloud文档的同时实施iCloud Drive / Files支持。 $(TeamIdentifierPrefix)

时间:2017-11-07 13:51:46

标签: ios icloud icloud-drive

正如标题所示,我想在现有应用程序上实现iCloud Drive支持,其中ubiquity容器以旧样式$(TeamIdentifierPrefix)作为前缀。对于我的生活,我无法让它发挥作用。

最初我尝试了Apple自己的步骤,详见此处:https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html#//apple_ref/doc/uid/TP40012094-CH2-SW20

遗憾的是,这并没有奏效。 (我记得每个版本增加Bundle版本)

按照这篇文章中提供的步骤:iCloud Drive Folder,我能够让我的应用程序显示在iCloud Drive中,但我现有的文档无法访问,因为它们位于例如X123F4563T8.com.example.app而不是新创建的iCloud.com.example.app。

我尝试了不同标识符配置的无数变体,试图让iCloud Drive指向旧的无处不在容器,但无济于事。

我的权利文件如下所示(使用我的应用程序自己的标识符):

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
    <string>iCloud.com.example.AppName</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
    <string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
    <string>iCloud.com.example.AppName</string>
</array>
<key>keychain-access-groups</key>
<array>
    <string>$(AppIdentifierPrefix)com.example.AppName</string>
</array>

第一个关键似乎是决定使用哪个ubiquity目录。

此前已设为:

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
    <string>$(TeamIdentifierPrefix)com.example.AppName</string>
</array>

我缩小搜索范围,发现这个密钥的值似乎是决定使用(旧式)iCloud文档的决定因素

 $(TeamIdentifierPrefix)com.example.AppName

或iCloud Drive,

 iCloud.com.example.AppName

为了完整起见,我的Info.plist中包含以下内容:

<key>iCloud.com.example.AppName</key>
<dict>
    <key>NSUbiquitousContainerIsDocumentScopePublic</key>
    <true/>
    <key>NSUbiquitousContainerName</key>
    <string>App Name For Drive</string>
    <key>NSUbiquitousContainerSupportedFolderLevels</key>
    <string>Any</string>
</dict>

我也没有忽视:

<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
    <string>iCloud.com.example.AppName</string>
</array>

但是,这个值似乎对结果没有影响。

1 个答案:

答案 0 :(得分:0)

为了使其正常工作,我的Info.plist中添加了以下条目:

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.com.Example.AppName</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerName</key>
        <string>Example App Name</string>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
    </dict>
</dict>

我的AppName.entitlements文件包含在其中:

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
    <string>$(TeamIdentifierPrefix)com.example.AppName</string>
    <string>iCloud.com.example.AppName</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
    <string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
    <string>$(TeamIdentifierPrefix)com.example.AppName</string>
</array>

既然我们都设置了能够访问这两个容器的功能,我在我的Info.plist中添加了2个我希望能够访问的iCloud无处不在的地址(旧式iCloud文档和更新的iCloud Drive): / p>

<key>UbiquitousContainers</key>
<array>
    <string>$(TeamIdentifierPrefix)com.example.AppName</string>
    <string>iCloud.com.example.AppName</string>
</array>

然后我将以下内容添加到常量文件中以便于访问:

struct UbiquityContainers {
    private static let ubiquityContainers : [String] = Bundle.main.object(forInfoDictionaryKey: "UbiquitousContainers") as! [String]
    static var iCloudDocuments : String {
        get {
            return ubiquityContainers[0]
        }
    }
    static var iCloudDrive : String {
        get {
            return ubiquityContainers[1]
        }
    }
}

我选择允许用户通过TabBar在2个容器之间切换。旧的iCloud Documents目录保存了我的应用程序的旧版本中的文档,这些文档需要在打开之前转换为新的文档格式,因此在我的情况下,对每个文件版本都有单独的视图。

var ubiquityContainer : String = UbiquityContainers.iCloudDrive
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    if(self.documentsInCloud) {
        if(item == self.iCloudDriveTabBarItem) {
            self.ubiquityContainer = UbiquityContainers.iCloudDrive
        } else if(item == self.iCloudDocumentsTabBarItem) {
            self.ubiquityContainer = UbiquityContainers.iCloudDocuments
        }
        self.startCloudQuery()
    }
}

我希望这可以帮助将来可能缺乏卵泡的人,因为他们散落在地上。 :)