Ejemplo n.º 1
0
        /// <summary>
        /// Adds the URL scheme to the plist.
        /// If the key already exists, the value is updated to the given value.
        /// If the key cannot be found, it is added.
        /// </summary>
        /// <param name="buddy">buddy - the plist helper to use.</param>
        /// <param name="key">Key - the url scheme key to look for</param>
        /// <param name="value">Value - the value of the scheme.</param>
        private static void AddURLScheme(PlistBuddyHelper buddy, string key, string value)
        {
            int index = 0;

            while (buddy.EntryValue(UrlTypes, index) != null)
            {
                string urlName = buddy.EntryValue(UrlTypes, index, UrlBundleName);

                if (key.Equals(urlName))
                {
                    // remove the existing value
                    buddy.RemoveEntry(UrlTypes, index, UrlScheme);
                    //add the array back
                    buddy.AddArray(UrlTypes, index, UrlScheme);
                    //add the value
                    buddy.AddString(PlistBuddyHelper.ToEntryName(UrlTypes, index, UrlScheme, 0),
                                    value);
                    return;
                }

                index++;
            }

            // not found, add new entry
            buddy.AddDictionary(UrlTypes, index);
            buddy.AddString(PlistBuddyHelper.ToEntryName(UrlTypes, index, UrlBundleName),
                            key);
            //add the array
            buddy.AddArray(UrlTypes, index, UrlScheme);
            //add the value
            buddy.AddString(PlistBuddyHelper.ToEntryName(UrlTypes, index, UrlScheme, 0),
                            value);
        }