Exemplo n.º 1
0
        public void AddiCloud(bool enableKeyValueStorage, bool enableiCloudDocument, bool enablecloudKit,
                              bool addDefaultContainers, string[] customContainers)
        {
            var ent = GetOrCreateEntitlementDoc();
            var val = (ent.root[ICloudEntitlements.ContainerIdKey] = new PlistElementArray()) as PlistElementArray;

            // Cloud document storage and CloudKit require specifying services.
            PlistElementArray ser = null;

            if (enableiCloudDocument || enablecloudKit)
            {
                ser = (ent.root[ICloudEntitlements.ServicesKey] = new PlistElementArray()) as PlistElementArray;
            }

            if (enableiCloudDocument)
            {
                val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue));
                ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesDocValue));
                var ubiquity =
                    (ent.root[ICloudEntitlements.UbiquityContainerIdKey] =
                         new PlistElementArray()) as PlistElementArray;

                if (addDefaultContainers)
                {
                    ubiquity.values.Add(new PlistElementString(ICloudEntitlements.UbiquityContainerIdValue));
                }

                if (customContainers != null && customContainers.Length > 0)
                {
                    // For cloud document, custom containers go in the ubiquity values.
                    for (var i = 0; i < customContainers.Length; i++)
                    {
                        ubiquity.values.Add(new PlistElementString(customContainers[i]));
                    }
                }
            }

            if (enablecloudKit)
            {
                if (addDefaultContainers && !enableiCloudDocument)
                {
                    val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue));
                }

                if (customContainers != null && customContainers.Length > 0)
                {
                    // For CloudKit, custom containers also go in the container id values.
                    for (var i = 0; i < customContainers.Length; i++)
                    {
                        val.values.Add(new PlistElementString(customContainers[i]));
                    }
                }

                ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesKitValue));
            }

            if (enableKeyValueStorage)
            {
                ent.root[ICloudEntitlements.KeyValueStoreKey] =
                    new PlistElementString(ICloudEntitlements.KeyValueStoreValue);
            }

            project.AddCapability(m_TargetGuid, PBXCapabilityType.iCloud, m_EntitlementFilePath, enablecloudKit);
        }