Пример #1
0
        private static void UpdatePlist(String pathToBuiltProject)
        {
            try
            {
                var fullPath = Path.Combine(pathToBuiltProject, InfoPlistFilePath);

                var plistDocument = new PlistDocument();
                plistDocument.ReadFromFile(fullPath);

                PlistElementDict nsAppTransportSecurityDict;
                PlistElement     nsAppTransportSecurityElement;
                if (plistDocument.root.values.TryGetValue(NsAppTransportSecurityKey, out nsAppTransportSecurityElement))
                {
                    nsAppTransportSecurityDict = nsAppTransportSecurityElement.AsDict();
                }
                else
                {
                    nsAppTransportSecurityDict = new PlistElementDict();
                    plistDocument.root.values.Add(NsAppTransportSecurityKey, nsAppTransportSecurityDict);
                }

                nsAppTransportSecurityDict[NsAllowsArbitraryLoadsKey] = new PlistElementBoolean(true);
                plistDocument.WriteToFile(fullPath);
            }
            catch { }
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// 更新内容到PList
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void Update(string key, string value, XcodeInfoPListType infoType = XcodeInfoPListType.StringInfo, bool isAdd = true)
        {
            PlistElementDict root = _plist.root;

            if (isAdd)
            {
                switch (infoType)
                {
                case XcodeInfoPListType.BoolInfo:
                    bool vb = bool.Parse(value);
                    if (root[key] != null)
                    {
                        root[key] = new PlistElementBoolean(vb);
                    }
                    else if (isAdd)
                    {
                        root.SetBoolean(key, vb);
                    }
                    break;

                case XcodeInfoPListType.IntInfo:
                    int vi = int.Parse(value);
                    if (root[key] != null)
                    {
                        root[key] = new PlistElementInteger(vi);
                    }
                    else if (isAdd)
                    {
                        root.SetInteger(key, vi);
                    }
                    break;

                case XcodeInfoPListType.StringInfo:
                    if (root[key] != null)
                    {
                        root[key] = new PlistElementString(value);
                    }
                    else
                    {
                        root.SetString(key, value);
                    }
                    break;
                }
            }
            else
            {
                root.values.Remove(key);
            }
        }
Пример #4
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);
        }
Пример #5
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            #if UNITY_IOS
            //Modify PList File and add AdMob ID
            string        plistPath = path + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            PlistElementDict rootDict = plist.root;

            string buildKey = "CFBundleVersion";
            rootDict.SetString(buildKey, "1");

            rootDict["GADApplicationIdentifier"] = new PlistElementString("ca-app-pub-8277769580123099~4622099382");

            PlistElementDict nsAppTransportSecurityDict = rootDict["NSAppTransportSecurity"].AsDict();
            nsAppTransportSecurityDict["NSAllowsArbitraryLoads"] = new PlistElementBoolean(true);

            rootDict["NSAppTransportSecurity"] = nsAppTransportSecurityDict;

            File.WriteAllText(plistPath, plist.WriteToString());


            //Add AdSupport.framework
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));

            string target = proj.GetUnityMainTargetGuid();

            proj.AddFrameworkToProject(target, "AdSupport.framework", true);

            File.WriteAllText(projPath, proj.WriteToString());
            #endif
        }
    }
        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);
        }
Пример #7
0
 public void SetBoolean(string key, bool val)
 {
     values[key] = new PlistElementBoolean(val);
 }
Пример #8
0
    [PostProcessBuild(1)]     // <- this is where the magic happens
    public static void OnPostProcessBuild(BuildTarget target, string buildPath)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        UnityEngine.Debug.Log("FusePostProcess Build Step - START");

        string[] frameworks = new string[] {
            "CoreTelephony.framework",
            "MessageUI.framework",
            "EventKit.framework",
            "EventKitUI.framework",
            "Twitter.framework",
            "Security.framework",
            "MobileCoreServices.framework",
            "GameKit.framework",
            "GLKit.framework",
            "JavaScriptCore.framework",
            "libsqlite3.tbd",
            "libxml2.tbd",
            "libz.tbd",
        };

        string[] weakFrameworks = new string[] {
            "Foundation.framework",
            "UIKit.framework",
            "UserNotifications.framework",
            "WebKit.framework",
            "AdSupport.framework",
            "Social.framework",
            "StoreKit.framework",
        };


        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProj     = new PBXProject();

        pbxProj.ReadFromFile(pbxProjPath);
        string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName());

        //Add Required Frameworks
        foreach (var framework in frameworks)
        {
            if (!pbxProj.ContainsFramework(targetGuid, framework, framework.EndsWith(".framework") ? "System/Library/Frameworks/" : "usr/lib/"))
            {
                pbxProj.AddFrameworkToProject(targetGuid, framework, false, framework.EndsWith(".framework") ? "System/Library/Frameworks/" : "usr/lib/");
            }
        }


        //Add Optional Frameworks
        foreach (var framework in weakFrameworks)
        {
            if (pbxProj.ContainsFramework(targetGuid, framework, framework.EndsWith(".framework") ? "System/Library/Frameworks/" : "usr/lib/"))
            {
                pbxProj.RemoveFrameworkFromProject(targetGuid, framework, framework.EndsWith(".framework") ? "System/Library/Frameworks/" : "usr/lib/");
            }

            pbxProj.AddFrameworkToProject(targetGuid, framework, true, framework.EndsWith(".framework") ? "System/Library/Frameworks/" : "usr/lib/");
        }

        Directory.CreateDirectory(buildPath + "/FrameworkRes");
        foreach (string frameworkPath in Directory.GetDirectories(Application.dataPath + FuseSDKEditor.IOS_NATIVE_LIBS, "*.embeddedframework", SearchOption.AllDirectories))
        {
            if (!Directory.Exists(frameworkPath + "/Resources"))
            {
                continue;
            }

            RecursiveDirCopy(frameworkPath + "/Resources", buildPath + "/FrameworkRes");

            //Don't iterate recursively.
            //Instead add all files and folders in the topmost directory as files.
            //This adds .bundle folders as files which is what's needed.
            foreach (string path in Directory.GetFiles(buildPath + "/FrameworkRes", "*", SearchOption.TopDirectoryOnly))
            {
                string localPath = path.Substring(buildPath.Length + 1);
                pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(localPath, localPath));
            }

            foreach (string path in Directory.GetDirectories(buildPath + "/FrameworkRes", "*", SearchOption.TopDirectoryOnly))
            {
                string localPath = path.Substring(buildPath.Length + 1);
                pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(localPath, localPath));
            }
        }

        //Add -ObjC linker flag
        pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");

        pbxProj.WriteToFile(pbxProjPath);


        //Info.plist processing
        string infoPlistPath = buildPath + "/Info.plist";

        var plistParser = new PlistDocument();

        plistParser.ReadFromFile(infoPlistPath);

        plistParser.root["fuse_ssl"] = new PlistElementBoolean(true);

        if (plistParser.root["NSCalendarsUsageDescription"] == null)
        {
            plistParser.root["NSCalendarsUsageDescription"] = new PlistElementString("Advertisement would like to create a calendar event.");
        }

        if (plistParser.root["NSPhotoLibraryUsageDescription"] == null)
        {
            plistParser.root["NSPhotoLibraryUsageDescription"] = new PlistElementString("Advertisement would like to store a photo.");
        }

        if (plistParser.root["NSCameraUsageDescription"] == null)
        {
            plistParser.root["NSCameraUsageDescription"] = new PlistElementString("Advertisement would like to use your camera.");
        }

        if (plistParser.root["NSMotionUsageDescription"] == null)
        {
            plistParser.root["NSMotionUsageDescription"] = new PlistElementString("Advertisement would like to use motion for interactive ad controls.");
        }

        PlistElementDict atsDict = (plistParser.root["NSAppTransportSecurity"] ?? (plistParser.root["NSAppTransportSecurity"] = new PlistElementDict())).AsDict();

        atsDict["NSAllowsLocalNetworking"]            = new PlistElementBoolean(true);
        atsDict["NSAllowsArbitraryLoadsInWebContent"] = new PlistElementBoolean(true);

        PlistElementArray appQueriesSchemes = (plistParser.root["LSApplicationQueriesSchemes"] ?? (plistParser.root["LSApplicationQueriesSchemes"] = new PlistElementArray())).AsArray();

        appQueriesSchemes.AddString("fb");
        appQueriesSchemes.AddString("instagram");
        appQueriesSchemes.AddString("tumblr");
        appQueriesSchemes.AddString("twitter");

        plistParser.WriteToFile(infoPlistPath);


        UnityEngine.Debug.Log("FusePostProcess - STOP");
    }
        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);
                    }
                }
            }
        }