/// <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); }
/// <summary> /// Updates the new project's Info.plist file to include an entry for the Url scheme mandated /// by the Google+ login. This means that the plist file needs to have an entry in the for /// indicated here: <see cref="https://developers.google.com/+/mobile/ios/getting-started#step_3_add_a_url_type"/> /// <para>This boils down to having an entry in the CFBundleURLTypes top level plist field with /// a CFBundleURLName equal to the bundle ID of the game, and a single element array for /// CFBundleURLSchemes also containing the bundle ID.</para> /// <para>We make use of the apple-provided PlistBuddy utility to edit the plist file.</para> /// </summary> /// <param name="pathToPlist">Path to plist.</param> private static void UpdateGeneratedInfoPlistFile(string pathToPlist) { PlistBuddyHelper buddy = PlistBuddyHelper.ForPlistFile(pathToPlist); // If the top-level UrlTypes field doesn't exist, add it here. if (buddy.EntryValue(UrlTypes) == null) { buddy.AddArray(UrlTypes); } AddURLScheme(buddy, BundleSchemeKey, GetBundleId()); AddURLScheme(buddy, ReverseClientIdSchemeKey, GetReverseClientId()); }
/// <summary> /// Finds the index of the CFBundleURLTypes array where the entry for Play Games is stored. If /// this is not present, a new entry will be appended to the end of this array. /// </summary> /// <returns>The index in the CFBundleURLTypes array corresponding to Play Games.</returns> /// <param name="buddy">The helper corresponding to the plist file.</param> private static int GamesUrlSchemeIndex(PlistBuddyHelper buddy) { int index = 0; while(buddy.EntryValue(UrlTypes, index) != null) { var urlName = buddy.EntryValue(UrlTypes, index, UrlBundleName); if (GetBundleId().Equals(urlName)) { return index; } index++; } // The current array does not contain the Games url scheme - add a value to the end. buddy.AddDictionary(UrlTypes, index); buddy.AddString(PlistBuddyHelper.ToEntryName(UrlTypes, index, UrlBundleName), GetBundleId()); return index; }
/// <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); }
/// <summary> /// Ensures the games URL scheme is well formed. This is done by removing the UrlScheme field /// and adding a fresh one in a known-good state. /// </summary> /// <param name="buddy">Buddy.</param> /// <param name="index">Index.</param> private static void EnsureGamesUrlScheme(PlistBuddyHelper buddy, int index) { buddy.RemoveEntry(UrlTypes, index, UrlScheme); buddy.AddArray(UrlTypes, index, UrlScheme); buddy.AddString(PlistBuddyHelper.ToEntryName(UrlTypes, index, UrlScheme, 0), GetBundleId()); }