internal static void ReadConfigInternal(bool errorOnNoConfig, string filename = null)
        {
            XcodeProjectPatcher.configValues = new Dictionary <string, string>();
            XcodeProjectPatcher.configFile   = (filename ?? XcodeProjectPatcher.FindConfig(errorOnNoConfig));
            if (XcodeProjectPatcher.configFile == null)
            {
                return;
            }
            PlistDocument plistDocument = new PlistDocument();

            plistDocument.ReadFromString(File.ReadAllText(XcodeProjectPatcher.configFile));
            PlistElementDict root = plistDocument.root;

            string[] pROJECT_KEYS = XcodeProjectPatcher.PROJECT_KEYS;
            for (int i = 0; i < pROJECT_KEYS.Length; i++)
            {
                string       text         = pROJECT_KEYS[i];
                PlistElement plistElement = root[text];
                if (plistElement != null)
                {
                    XcodeProjectPatcher.configValues[text] = plistElement.AsString();
                    if (object.Equals(text, "BUNDLE_ID"))
                    {
                        XcodeProjectPatcher.allBundleIds.Add(plistElement.AsString());
                    }
                }
            }
        }
Exemple #2
0
        public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            PrepareProject(buildPath);

            // Make sure that the proper location usage string is in Info.plist

            const string locationKey = "NSLocationWhenInUseUsageDescription";

            var plistPath = Path.Combine(buildPath, "Info.plist");
            var plist     = new PlistDocument();

            plist.ReadFromFile(plistPath);
            PlistElement element = plist.root[locationKey];
            var          usage   = MoPubConsent.LocationAwarenessUsageDescription;

            // Add or overwrite the key in the info.plist file if necessary.
            // (Note:  does not overwrite if the string has been manually changed in the Xcode project and our string is just the default.)
            if (element == null || usage != element.AsString() && usage != MoPubConsent.DefaultLocationAwarenessUsage)
            {
                plist.root.SetString(locationKey, usage);
                plist.WriteToFile(plistPath);
            }
        }
Exemple #3
0
        public static void PostprocessBuild(BuildTarget buildTarget, string buildPath)
        {
            if (IdfaAuthorizationUtils.IsAttEnabled())
            {
                if (buildTarget != BuildTarget.iOS)
                {
                    return;
                }


                var plistPath = Path.Combine(buildPath, "Info.plist");
                var plist     = new PlistDocument();
                plist.ReadFromFile(plistPath);
                PlistElement element = plist.root[UserTrackingUsageDescriptionKey];


                PlistElementArray skAdNetworks = plist.root.CreateArray("SKAdNetworkItems");

                PlistElementDict fbSkanId = skAdNetworks.AddDict();
                fbSkanId.SetString("SKAdNetworkIdentifier", "v9wttpbfk9.skadnetwork");
                PlistElementDict fbSkanSecondaryId = skAdNetworks.AddDict();
                fbSkanSecondaryId.SetString("SKAdNetworkIdentifier", "n38lu8286q.skadnetwork");
                PlistElementDict snapSkanId = skAdNetworks.AddDict();
                snapSkanId.SetString("SKAdNetworkIdentifier", "424m5254lk.skadnetwork");


                plist.root.SetString(UserTrackingUsageDescriptionKey, IdfaAuthorizationConstants.UserTrackingUsageDescription);
                plist.WriteToFile(plistPath);
            }
        }
        /// <summary>
        /// plistの更新をする
        /// </summary>
        /// <param name="buildPath"></param>
        /// <param name="settings"></param>
        private static void UpdatePlist(string buildPath, GoogleSettings settings)
        {
    #if UNITY_IOS
            PlistDocument plist    = new PlistDocument();
            string        filePath = Path.Combine(buildPath, "Info.plist");
            plist.ReadFromFile(filePath);

            PlistElement bundleUrlTypes = null;
            if (!plist.root.values.TryGetValue("CFBundleURLTypes", out bundleUrlTypes))
            {
                bundleUrlTypes = plist.root.CreateArray("CFBundleURLTypes");
            }

            // set url scheme
            PlistElementDict urlSchemeDict = bundleUrlTypes.AsArray().AddDict();
            urlSchemeDict.SetString("CFBundleTypeRole", "Editor");
            urlSchemeDict.CreateArray("CFBundleURLSchemes").AddString(settings.IOS.URLScheme);

            // set bundle id
            PlistElementDict bundleIdDict = bundleUrlTypes.AsArray().AddDict();
            bundleIdDict.SetString("CFBundleTypeRole", "Editor");
#if UNITY_5_6_OR_NEWER
            bundleIdDict.CreateArray("CFBundleURLSchemes").AddString(Application.identifier);
#else
            bundleIdDict.CreateArray("CFBundleURLSchemes").AddString(Application.bundleIdentifier);
#endif
            plist.WriteToFile(filePath);
#endif
        }
Exemple #5
0
 private static XElement WriteElement(PlistElement el)
 {
     if (el is PlistElementBoolean)
     {
         var realEl = el as PlistElementBoolean;
         return(new XElement(realEl.value ? "true" : "false"));
     }
     if (el is PlistElementInteger)
     {
         var realEl = el as PlistElementInteger;
         return(new XElement("integer", realEl.value.ToString()));
     }
     if (el is PlistElementString)
     {
         var realEl = el as PlistElementString;
         return(new XElement("string", realEl.value));
     }
     if (el is PlistElementReal)
     {
         var realEl = el as PlistElementReal;
         return(new XElement("real", realEl.value.ToString()));
     }
     if (el is PlistElementDate)
     {
         var realEl = el as PlistElementDate;
         return(new XElement("date", realEl.value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")));
     }
     if (el is PlistElementDict)
     {
         var realEl  = el as PlistElementDict;
         var dictXml = new XElement("dict");
         foreach (var kv in realEl.values)
         {
             var keyXml   = new XElement("key", kv.Key);
             var valueXml = WriteElement(kv.Value);
             if (valueXml != null)
             {
                 dictXml.Add(keyXml);
                 dictXml.Add(valueXml);
             }
         }
         return(dictXml);
     }
     if (el is PlistElementArray)
     {
         var realEl   = el as PlistElementArray;
         var arrayXml = new XElement("array");
         foreach (var v in realEl.values)
         {
             var elXml = WriteElement(v);
             if (elXml != null)
             {
                 arrayXml.Add(elXml);
             }
         }
         return(arrayXml);
     }
     return(null);
 }
Exemple #6
0
        private static void AddPlistVariables(string projectPath)
        {
            var infoPlist     = new PlistDocument();
            var infoPlistPath = projectPath + "/Info.plist";

            infoPlist.ReadFromFile(infoPlistPath);

            foreach (var variable in ISD_Settings.Instance.PlistVariables)
            {
                PlistElement plistVariable = null;
                switch (variable.Type)
                {
                case ISD_PlistKeyType.String:
                    plistVariable = new PlistElementString(variable.StringValue);
                    break;

                case ISD_PlistKeyType.Integer:
                    plistVariable = new PlistElementInteger(variable.IntegerValue);
                    break;

                case ISD_PlistKeyType.Boolean:
                    plistVariable = new PlistElementBoolean(variable.BooleanValue);
                    break;

                case ISD_PlistKeyType.Array:
                    plistVariable = CreatePlistArray(variable);
                    break;

                case ISD_PlistKeyType.Dictionary:
                    plistVariable = CreatePlistDict(variable);
                    break;
                }

                infoPlist.root[variable.Name] = plistVariable;
            }


            // Get root
            PlistElementDict rootDict = infoPlist.root;

            /*
             * // Set encryption usage boolean
             * string encryptKey = "ITSAppUsesNonExemptEncryption";
             * rootDict.SetBoolean(encryptKey, false);*/

            // remove exit on suspend if it exists.
            string exitsOnSuspendKey = "UIApplicationExitsOnSuspend";

            if (rootDict.values.ContainsKey(exitsOnSuspendKey))
            {
                rootDict.values.Remove(exitsOnSuspendKey);
            }

            infoPlist.WriteToFile(infoPlistPath);
        }
Exemple #7
0
        static PlistElementArray GetOrCreateArray(PlistElementDict dict, string key)
        {
            PlistElement array = dict[key];

            if (array != null)
            {
                return(array.AsArray());
            }
            else
            {
                return(dict.CreateArray(key));
            }
        }
Exemple #8
0
        static void AddPlistVariables(string projectPath)
        {
            var infoPlist     = new PlistDocument();
            var infoPlistPath = projectPath + "/Info.plist";

            infoPlist.ReadFromFile(infoPlistPath);

            foreach (var variable in XCodeProjectSettings.Instance.PlistVariables)
            {
                PlistElement plistVariable = null;
                switch (variable.Type)
                {
                case InfoPlistKeyType.String:
                    plistVariable = new PlistElementString(variable.StringValue);
                    break;

                case InfoPlistKeyType.Integer:
                    plistVariable = new PlistElementInteger(variable.IntegerValue);
                    break;

                case InfoPlistKeyType.Boolean:
                    plistVariable = new PlistElementBoolean(variable.BooleanValue);
                    break;

                case InfoPlistKeyType.Array:
                    plistVariable = CreatePlistArray(variable);
                    break;

                case InfoPlistKeyType.Dictionary:
                    plistVariable = CreatePlistDict(variable);
                    break;
                }

                infoPlist.root[variable.Name] = plistVariable;
            }

            // Get root
            var rootDict = infoPlist.root;

            // remove exit on suspend if it exists.
            var exitsOnSuspendKey = "UIApplicationExitsOnSuspend";

            if (rootDict.values.ContainsKey(exitsOnSuspendKey))
            {
                rootDict.values.Remove(exitsOnSuspendKey);
            }

            infoPlist.WriteToFile(infoPlistPath);
        }
Exemple #9
0
    private static void DoAddSKAdNetworkItemsToInfo(string projectPath)
    {
        string infoPlistPath = Path.Combine(projectPath, "Info.plist");

        PlistDocument plistDoc = new PlistDocument();

        plistDoc.ReadFromFile(infoPlistPath);
        if (plistDoc.root != null)
        {
            PlistElementDict rootDict = plistDoc.root;

            PlistElement elementSKAdNetworkItems = rootDict["SKAdNetworkItems"];

            if (null == elementSKAdNetworkItems)
            {
                rootDict["SKAdNetworkItems"] = new PlistElementArray();

                elementSKAdNetworkItems = rootDict["SKAdNetworkItems"];
            }
            else
            {
                PlistElementArray arrayAdNetworkItems = elementSKAdNetworkItems.AsArray();
                int count = arrayAdNetworkItems.values.Count;
                arrayAdNetworkItems.values.RemoveRange(0, count);
            }

            PlistElementArray arrayItems = elementSKAdNetworkItems.AsArray();

            PlistElementArray addAdNetworks = DoGetAdNetworks();

            for (int i = 0; i < addAdNetworks.values.Count; i++)
            {
                PlistElementDict item = addAdNetworks.values[i] as PlistElementDict;
                arrayItems.values.Add(item);
            }

            plistDoc.WriteToFile(infoPlistPath);
        }
        else
        {
            Debug.LogError("Error: Can't open " + infoPlistPath);
        }
    }
Exemple #10
0
    private static PlistElementArray DoGetAdNetworks()
    {
        string adNetworksPlistPath = Path.Combine(DoGetProjectFolder(), "Assets/10.Tools/AppTrackingTransparency/Editor/SKAdNetworkItems.plist");

        PlistDocument plistDoc = new PlistDocument();

        plistDoc.ReadFromFile(adNetworksPlistPath);

        PlistElement elementSKAdNetworkItems = plistDoc.root["SKAdNetworkItems"];

        if (null == elementSKAdNetworkItems)
        {
            plistDoc.root["SKAdNetworkItems"] = new PlistElementArray();

            elementSKAdNetworkItems = plistDoc.root["SKAdNetworkItems"];
        }

        PlistElementArray arrayItems = elementSKAdNetworkItems.AsArray();

        return(arrayItems);
    }
 /// <summary>
 /// Utility to get value of a PlistElement as string
 /// </summary>
 private static string ValueToString(PlistElement element)
 {
     if (element is PlistElementString)
     {
         return(((PlistElementString)element).value);
     }
     else if (element is PlistElementInteger)
     {
         return(((PlistElementInteger)element).value.ToString());
     }
     else if (element is PlistElementBoolean)
     {
         return(((PlistElementBoolean)element).value.ToString());
         //  } else if (element is PlistElementDict) {
         //      Dictionary<string, PlistElement> values;
         //      return ((PlistElementDict)element).values.Select(x => x.Key + " : " + ValueToString(x.Value)).Join();
     }
     else
     {
         return(element.ToString());
     }
 }
        private static void AddPlistVariables(string projectPath)
        {
            var infoPlist     = new PlistDocument();
            var infoPlistPath = projectPath + "/Info.plist";

            infoPlist.ReadFromFile(infoPlistPath);

            foreach (var variable in ISD_Settings.Instance.PlistVariables)
            {
                PlistElement plistVariable = null;
                switch (variable.Type)
                {
                case ISD_PlistKeyType.String:
                    plistVariable = new PlistElementString(variable.StringValue);
                    break;

                case ISD_PlistKeyType.Integer:
                    plistVariable = new PlistElementInteger(variable.IntegerValue);
                    break;

                case ISD_PlistKeyType.Boolean:
                    plistVariable = new PlistElementBoolean(variable.BooleanValue);
                    break;

                case ISD_PlistKeyType.Array:
                    plistVariable = CreatePlistArray(variable);
                    break;

                case ISD_PlistKeyType.Dictionary:
                    plistVariable = CreatePlistDict(variable);
                    break;
                }

                infoPlist.root[variable.Name] = plistVariable;
            }

            infoPlist.WriteToFile(infoPlistPath);
        }
        private static void UpdatePlist(string pathToBuiltProject, string clientId)
        {
            if (pathToBuiltProject != null && pathToBuiltProject.Length > 0)
            {
                string plistFilePath = Path.Combine(pathToBuiltProject, "Info.plist");

                if (File.Exists(plistFilePath))
                {
                    PlistDocument plistDocument = new PlistDocument();

                    plistDocument.ReadFromFile(plistFilePath);

                    // Add url schemes

                    PlistElement urlTypesElement = plistDocument.root["CFBundleURLTypes"];

                    if (urlTypesElement == null)
                    {
                        plistDocument.root["CFBundleURLTypes"] = new PlistElementArray();
                    }

                    PlistElementArray urlTypes = plistDocument.root["CFBundleURLTypes"].AsArray();

                    bool updated = false;

                    if (urlTypes != null)
                    {
                        PlistElementDict dict = urlTypes.AddDict();

                        PlistElementArray array = dict.CreateArray("CFBundleURLSchemes");

                        array.AddString("us" + clientId);
                        array.AddString("ep" + clientId);

                        updated = true;
                    }

                    // Add allow arbitrary loads

                    PlistElement appTransportSecurityElement = plistDocument.root["NSAppTransportSecurity"];

                    if (appTransportSecurityElement == null)
                    {
                        plistDocument.root["NSAppTransportSecurity"] = new PlistElementDict();
                    }

                    PlistElementDict appTransportSecurityElementDict = plistDocument.root["NSAppTransportSecurity"].AsDict();

                    if (appTransportSecurityElementDict != null)
                    {
                        appTransportSecurityElementDict["NSAllowsArbitraryLoads"] = new PlistElementBoolean(true);
                    }

                    // Add camera usage description for iOS 10

                    PlistElement cameraUsageDescriptionElement = plistDocument.root["NSCameraUsageDescription"];

                    if (cameraUsageDescriptionElement == null)
                    {
                        plistDocument.root["NSCameraUsageDescription"] = new PlistElementString("HeyPlay requires access to the camera");
                    }

                    // Add microphone usage description for iOS 10

                    PlistElement microphoneUsageDescriptionElement = plistDocument.root["NSMicrophoneUsageDescription"];

                    if (microphoneUsageDescriptionElement == null)
                    {
                        plistDocument.root["NSMicrophoneUsageDescription"] = new PlistElementString("HeyPlay requires access to the microphone");
                    }

                    // Add photo library usage description for iOS 10

                    PlistElement photoLibraryUsageDescriptionElement = plistDocument.root["NSPhotoLibraryUsageDescription"];

                    if (photoLibraryUsageDescriptionElement == null)
                    {
                        plistDocument.root["NSPhotoLibraryUsageDescription"] = new PlistElementString("HeyPlay requires access to the photo library");
                    }

                    // Add contact usage description for iOS 10

                    PlistElement contactUsageDescriptionElement = plistDocument.root["NSContactsUsageDescription"];

                    if (contactUsageDescriptionElement == null)
                    {
                        plistDocument.root["NSContactsUsageDescription"] = new PlistElementString("HeyPlay requires access to the contacts");
                    }

                    if (updated)
                    {
                        plistDocument.WriteToFile(plistFilePath);
                    }
                }
            }
        }
Exemple #14
0
    public static void AddDataToPlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget == BuildTarget.iOS)
        {
                        #if UNITY_IOS
            //Build Data From Google Services File
            PlistDocument googlePlist = new PlistDocument();
            googlePlist.ReadFromString(File.ReadAllText(pathToBuiltProject + "/" + googleInfoPlistFilePath));
            string fireAppID = googlePlist.root ["REVERSED_CLIENT_ID"].AsString();

            // Get plist
            string        plistPath = pathToBuiltProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            // Get root
            PlistElementDict rootDict = plist.root;


            //1. Build Data
            PlistElementArray bundleUrlSchemaArr1 = new PlistElementArray();
            bundleUrlSchemaArr1.AddString(fireAppID);

            PlistElementArray bundleUrlSchemaArr2 = new PlistElementArray();
            bundleUrlSchemaArr2.AddString(Application.identifier);

            var               bundleUrlRootKey = "CFBundleURLTypes";
            PlistElement      bundleUrlData    = rootDict [bundleUrlRootKey];
            PlistElementArray bundleUrlAsArray = null;
            if (bundleUrlData == null)
            {
                bundleUrlAsArray = new PlistElementArray();
            }
            else
            {
                bundleUrlAsArray = bundleUrlData.AsArray();
            }

            //2..
            PlistElementDict bundleUrlItem1 = new PlistElementDict();
            bundleUrlItem1 ["CFBundleTypeRole"]   = new PlistElementString("Editor");
            bundleUrlItem1 ["CFBundleURLName"]    = new PlistElementString("google");
            bundleUrlItem1 ["CFBundleURLSchemes"] = bundleUrlSchemaArr1;

            bundleUrlAsArray.values.Add(bundleUrlItem1);

            //3.. (A hack for login crash issue)
            PlistElementDict bundleUrlItem2 = new PlistElementDict();
            bundleUrlItem2 ["CFBundleTypeRole"]   = new PlistElementString("Editor");
            bundleUrlItem2 ["CFBundleURLName"]    = new PlistElementString("lcgoogle");
            bundleUrlItem2 ["CFBundleURLSchemes"] = bundleUrlSchemaArr2;

            bundleUrlAsArray.values.Add(bundleUrlItem2);

            //3..
            rootDict [bundleUrlRootKey] = bundleUrlAsArray;

            // // ~~ Add GoogleSignIn Data // //


            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());

            Debug.Log("LCGoogleSignIn: iOS: AddDataToPlist for callbacks: Success");
                        #endif
        }
    }
Exemple #15
0
    private static void AddCapabilitiesFieldToInfoPlist(string pathToBuildProject, string key, string value, PlistElement type)
    {
        string plistFilePath = Path.Combine(pathToBuildProject, "Info.plist");

        if (File.Exists(plistFilePath) == false)
        {
            return;
        }
        if (key.Length < 1 || value.Length < 1)
        {
            return;
        }

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistFilePath);
        PlistElementDict rootDic = plist.root;

        if (rootDic.values.ContainsKey(key) == false)
        {
            if (type is PlistElementString)
            {
                rootDic.SetString(key, value);
            }
            else if (type is PlistElementArray)
            {
                rootDic.CreateArray(key).AddString(value);
            }
        }
        else
        {
            if (type is PlistElementString)
            {
                rootDic.SetString(key, value);
            }
            else if (type is PlistElementArray)
            {
                PlistElementArray array = rootDic.values[key].AsArray();
                foreach (PlistElement item in array.values)
                {
                    if (item.AsString() == value)
                    {
                        Debug.LogWarningFormat("alread exist {0}:{1} in Info.plist", key, value);
                        return;
                    }
                }
                array.AddString(value);
            }
        }
        File.WriteAllText(plistFilePath, plist.WriteToString());
    }