Пример #1
0
    public static void ApplyDataBinding(string pbxmod, string rootpath, PBXProject proj, string target)
    {
        DataBinding dataBinding = new DataBinding(pbxmod);

        ApplyData(dataBinding.libs, (valueOne, valueTwo) => {
            proj.AddFileToBuild(target, proj.AddFile("usr/lib/" + valueOne, "Frameworks/" + valueOne, PBXSourceTree.Sdk));
        });
        ApplyData(dataBinding.frameworks, (valueOne, valueTwo) => {
            proj.AddFrameworkToProject(target, valueOne, false);
        });
        ApplyData(dataBinding.plist, (valueOne, valueTwo) => {
            //修改plist

            string plistPath    = rootpath + "/Info.plist";
            PlistDocument plist = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));
            PlistElementDict rootDict = plist.root;
            if (valueTwo == "True" || valueTwo == "False")
            {
                rootDict.SetBoolean(valueOne, bool.Parse(valueTwo));
                plist.WriteToFile(plistPath);
                return;
            }
            if (ChargeIsNumber(valueTwo))
            {
                rootDict.SetInteger(valueOne, int.Parse(valueTwo));
                plist.WriteToFile(plistPath);
                return;
            }
            // 语音听写需要开启的权限
            rootDict.SetString(valueOne, valueTwo);
            //保存plist
            plist.WriteToFile(plistPath);
        });
        Debug.Log("修改PLIST成功!");
        ApplyData(dataBinding.bitcode, (valueOne, ValueTwo) => {
            proj.SetBuildProperty(target, "ENABLE_BITCODE", valueOne);
        });
        Debug.Log("修改ENABLE_BITCODE成功!");
        ApplyData(dataBinding.code_sign_identity, (valueOne, ValueTwo) => {
            proj.SetBuildProperty(target, "CODE_SIGN_IDENTITY", valueOne + ":" + ValueTwo);
        });
        Debug.Log("修改CODE_SIGN_IDENTITY成功!");
        ApplyData(dataBinding.provisioning_profile_specifier, (valueOne, ValueTwo) => {
            proj.SetBuildProperty(target, "PROVISIONING_PROFILE_SPECIFIER", valueOne);
        });
        Debug.Log("修改PROVISIONING_PROFILE_SPECIFIER成功!");
        ApplyData(dataBinding.framework_search_paths, (valueOne, ValueTwo) => {
            proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", valueOne);
        });
        Debug.Log("修改FRAMEWORK_SEARCH_PATHS成功!");
        //设置框架路径时,无法实现在Xcode中依次添加各个路径,添加一个可以,添加第二个覆盖第一个
        ApplyData(dataBinding.other_ldflags, (valueOne, ValueTwo) => {
            proj.SetBuildProperty(target, "OTHER_LDFLAGS", valueOne);
        });
        Debug.Log("修改OTHER_LDFLAGS成功!");
    }
        static void AddLanguage(string path, params string[] languages)
        {
            var plistPath = Path.Combine(path, "Info.plist");
            var plist     = new PlistDocument();

            plist.ReadFromFile(plistPath);

            var localizationKey = "CFBundleLocalizations";

            var localizations = plist.root.values
                                .Where(kv => kv.Key == localizationKey)
                                .Select(kv => kv.Value)
                                .Cast <PlistElementArray> ()
                                .FirstOrDefault();

            if (localizations == null)
            {
                localizations = plist.root.CreateArray(localizationKey);
            }

            foreach (var language in languages)
            {
                if (localizations.values.Select(el => el.AsString()).Contains(language) == false)
                {
                    localizations.AddString(language);
                }
            }

            plist.WriteToFile(plistPath);
        }
Пример #3
0
        public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
        {
            if (buildTarget == BuildTarget.iOS)
            {
                string     projPath = PBXProject.GetPBXProjectPath(path);
                PBXProject proj     = new PBXProject();
                proj.ReadFromString(File.ReadAllText(projPath));

                // old method, for Unity 2019.2 and below
                //string target = proj.TargetGuidByName("Unity-iPhone");

                // new method
                string target = proj.GetUnityFrameworkTargetGuid();

                proj.AddFrameworkToProject(target, "StoreKit.framework", false);
                proj.AddFrameworkToProject(target, "MediaPlayer.framework", false);
                File.WriteAllText(projPath, proj.WriteToString());

                /* Info.plist */

                // Read the Info.plist file
                string        plistPath = path + "/Info.plist";
                PlistDocument plist     = new PlistDocument();
                plist.ReadFromString(File.ReadAllText(plistPath));

                // Get root of plist
                PlistElementDict rootDict = plist.root;

                // add the Apple Music privacy prompt entry
                rootDict.SetString("NSAppleMusicUsageDescription", "iOS Music would like to access this device's media library to play music.");

                //Write out the Info.plist file
                plist.WriteToFile(plistPath);
            }
        }
Пример #4
0
        public static void AddStringKey(string buildPath, string key, string value)
        {
            PlistDocument plist = GetInfoPlist(buildPath);

            plist.root.SetString(key, value);
            plist.WriteToFile(GetInfoPlistPath(buildPath));
        }
Пример #5
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 { }
        }
Пример #6
0
    private static void OnIOSBuildFinished(BuildTarget r_target, string r_pathToBuiltProject)
    {
        string     projPath   = PBXProject.GetPBXProjectPath(r_pathToBuiltProject);
        PBXProject pbxProject = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(projPath));
        string targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

        //添加它喵的framework
        string[] frameworks =
        {
            "Security.framework", "SystemConfiguration.framework", "CoreTelephony.framework", "CFNetwork.framework"
        };
        foreach (var framework in frameworks)
        {
            AddFramework(pbxProject, targetGuid, framework, false);
        }

        //添加它喵的lib
        AddLib(pbxProject, targetGuid, "libsqlite3.tbd");
        AddLib(pbxProject, targetGuid, "libc++.tbd");
        AddLib(pbxProject, targetGuid, "libz.tbd");

        // 添加flag
        pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-Objc -all_load");

        // 应用修改
        File.WriteAllText(projPath, pbxProject.WriteToString());

        // 修改Info.plist文件
        var plistPath = Path.Combine(r_pathToBuiltProject, "Info.plist");
        var plist     = new PlistDocument();

        plist.ReadFromFile(plistPath);

        var key = plist.root.CreateArray("LSApplicationQueriesSchemes");

        key.AddString("wechat");
        key.AddString("weixin");

        plist.WriteToFile(plistPath);

        string pPath = Application.dataPath.Replace("Assets", string.Empty);

        if (ReplaceFile($"{pPath}XCClasses/UnityAppController.h", $"{r_pathToBuiltProject}/Classes/UnityAppController.h"))
        {
            if (ReplaceFile($"{pPath}XCClasses/UnityAppController.mm", $"{r_pathToBuiltProject}/Classes/UnityAppController.mm"))
            {
                //
            }
            else
            {
                EditorUtility.DisplayDialog("错误", "替换UnityAppController.mm失败,请检查XCClasses文件夹", "ok");
            }
        }
        else
        {
            EditorUtility.DisplayDialog("错误", "替换UnityAppController.h失败,请检查XCClasses文件夹", "ok");
        }
    }
Пример #7
0
        private static void AddPushEntitlement(string path, PBXProject project, string target)
        {
            var entitlements = new PlistDocument();

            string entitlementsFilename     = MainTargetName + ".entitlements";
            string entitlementsRelativePath = MainTargetName + "/" + entitlementsFilename;
            string entitlementsPath         = path + "/" + entitlementsRelativePath;

            if (File.Exists(entitlementsPath))
            {
                entitlements.ReadFromFile(entitlementsPath);
            }

            if (entitlements.root["aps-environment"] != null)
            {
                return;
            }
            else
            {
                entitlements.root.SetString("aps-environment", "development");
            }

            project.AddFile(entitlementsRelativePath, entitlementsFilename);
            entitlements.WriteToFile(entitlementsPath);

            project.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", entitlementsRelativePath);
        }
Пример #8
0
    static void IOS(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        string projectPath = PBXProject.GetPBXProjectPath(path);

        PBXProject pbxProject = new PBXProject();

        pbxProject.ReadFromFile(projectPath);

        //Exception: Calling TargetGuidByName with name='Unity-iPhone' is deprecated.【解決策】
        //https://koujiro.hatenablog.com/entry/2020/03/16/050848
        string target = pbxProject.GetUnityMainTargetGuid();


        //pbxProject.AddCapability(target, PBXCapabilityType.InAppPurchase);

        // Plistの設定のための初期化
        var plistPath = Path.Combine(path, "Info.plist");
        var plist     = new PlistDocument();

        plist.ReadFromFile(plistPath);

        plist.WriteToFile(plistPath);
        pbxProject.WriteToFile(projectPath);
    }
    public static void OnPreProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target == BuildTarget.iOS)
        {
            var path       = PBXProject.GetPBXProjectPath(pathToBuiltProject);
            var pbxProject = new PBXProject();
            pbxProject.ReadFromFile(path);
            var targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
#if USE_IOS_SIMULATOR
            RemoveFileFromProject(pbxProject, targetGuid, "libassimp.release.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libirrxml.release.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libstb_image.release.a");
#else
            RemoveFileFromProject(pbxProject, targetGuid, "libassimp.debug.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libirrxml.debug.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libstb_image.debug.a");
            pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
#endif
            pbxProject.AddFrameworkToProject(targetGuid, "libz.dylib", true);
            pbxProject.WriteToFile(path);
#if USE_IOS_FILES_SHARING
            var plistPath = pathToBuiltProject + "/info.plist";
            var plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            var dict = plist.root.AsDict();
            dict.SetBoolean("UIFileSharingEnabled", true);
            plist.WriteToFile(plistPath);
#endif
        }
    }
        static void AddAppEntitlements(string projectPath, PBXProject project, string target)
        {
            var existingEntitlementsFiles = project.GetBuildPropertyValues(target, "CODE_SIGN_ENTITLEMENTS");

            if (existingEntitlementsFiles.Count == 0)
            {
                project.AddFileToBuild(target,
                                       project.AddFile("app.entitlements", "app.entitlements", PBXSourceTree.Source));
                project.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "app.entitlements");
                existingEntitlementsFiles.Add("app.entitlements");
            }
            foreach (var entitlementsSetting in existingEntitlementsFiles)
            {
                var entitlementsFilePath = Path.Combine(projectPath, entitlementsSetting);
                var entitlements         = new PlistDocument();
                if (File.Exists(entitlementsFilePath))
                {
                    entitlements.ReadFromFile(entitlementsFilePath);
                }

                if (GetSocialSettings.IsRichPushNotificationsEnabled && GetSocialSettings.IsIosPushEnabled)
                {
                    ConfigureAppGroups(entitlements);
                }
                ConfigureAssociatedDomains(entitlements);
                ConfigurePushNotifications(entitlements);

                entitlements.WriteToFile(entitlementsFilePath);
            }
        }
Пример #11
0
    // plist編集.
    static void EditPlist(string plistPath)
    {
        Debug.Log(">>>>>>>> EditPlist");
        var plist = new PlistDocument();
        plist.ReadFromFile(plistPath);

        // ローカリゼーション
        plist.root.SetString("CFBundleDevelopmentRegion", "ja_JP");

        if (PlayerSettings.applicationIdentifier != "com.smilelab.seven") {
            // URL Schemaを入れ替える
            foreach (var urlTypes in plist.root.values["CFBundleURLTypes"].AsArray().values) {
                var dict = urlTypes.AsDict ();
                var urls = dict.values ["CFBundleURLSchemes"].AsArray ();
                foreach (var url in urls.values.ToArray()) {
                    if (url.AsString () == "com.smilelab.seven") {
                        urls.values.Remove (url);
                        urls.AddString ("com.smilelab.devseven");
                    }
                }
            }
        }

        // 保存
        plist.WriteToFile(plistPath);
    }
        private static void EditPlist(string projectPath)
        {
            var clientConfig = AssetDatabase.LoadAssetAtPath(
                "Assets/Config/ClientConfig.asset",
                typeof(ClientConfig)) as ClientConfig;

            var product = clientConfig.Product;

            var plistFile = Path.Combine(projectPath, "Info.plist");
            var plist     = new PlistDocument();

            plist.ReadFromFile(plistFile);

            plist.root.SetString("CFBundleName", product.ProductName);
            plist.root.SetString("CFBundleDisplayName", product.DisplayName);
            plist.root.SetString("CFBundleDevelopmentRegion", "zh_CN");

            var schemes = plist.root.CreateArray("LSApplicationQueriesSchemes");

            schemes.AddString("weixin");
            schemes.AddString("wechat");
            schemes.AddString("dmmttigd");

            plist.WriteToFile(plistFile);
        }
        static void PostProcessBuild(BuildTarget target, string pathToBuildProject)
        {
            if (target == BuildTarget.iOS)
            {
#if UNITY_IOS
                //Xcode
                Debug.Log("PostProcessBuild IronSource Xcode");
                string     projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
                PBXProject pbxProj  = new PBXProject();
                pbxProj.ReadFromFile(projPath);
                string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName());
                pbxProj.AddFrameworkToProject(targetGuid, "AdSupport.framework", false);

                //Plist
                Debug.Log("PostProcessBuild IronSource Plist");
                string        plistPath = pathToBuildProject + "/Info.plist";
                PlistDocument plist     = new PlistDocument();
                plist.ReadFromString(File.ReadAllText(plistPath));
                PlistElementDict rootDict = plist.root;
                var dic = rootDict.CreateDict("NSAppTransportSecurity");
                dic.SetBoolean("NSAllowsArbitraryLoads", true);

                plist.WriteToFile(plistPath);
#endif
            }
        }
Пример #14
0
        private static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject)
        {
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            string     _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
            PBXProject project   = new PBXProject();

            project.ReadFromString(File.ReadAllText(_projPath));
            string targetGuid = project.TargetGuidByName("Unity-iPhone");

            //project.AddFrameworkToProject(targetGuid, "Security.framework", false);

            project.WriteToFile(_projPath);


            // plist
            string        plistPath = pathToBuildProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));
            PlistElementDict rootDict = plist.root;

            PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity");

            dictTmp.SetBoolean("NSAllowsArbitraryLoads", true);

            // 保存plist
            plist.WriteToFile(plistPath);
        }
    void SetBaseViewController(string path)
    {
        var _InfoPlistPath = Path.Combine(path, "Info.plist");
        var _InfoPlist     = new PlistDocument();

        _InfoPlist.ReadFromFile(_InfoPlistPath);
        _InfoPlist.root.SetBoolean("UIStatusBarHidden", false);
        _InfoPlist.WriteToFile(_InfoPlistPath);

        string _UnityViewControllerBaseFile = Path.Combine(path, "Classes/UI/UnityViewControllerBaseiOS.mm");

        if (!File.Exists(_UnityViewControllerBaseFile))
        {
            _UnityViewControllerBaseFile = Path.Combine(path, "Classes/UI/UnityViewControllerBase+iOS.mm");
        }
        string _UnityViewControllerBaseFileContent = File.ReadAllText(_UnityViewControllerBaseFile);
        string _OldTextInFile    = "    return _PrefersStatusBarHidden;";
        string _NewTextToReplace = "    CGSize size = [UIScreen mainScreen].bounds.size;\n" +
                                   "    if (size.width / size.height > 2.15f) {\n" +
                                   "        return NO;\n" +
                                   "    } else {\n" +
                                   "        return YES;\n" +
                                   "    }";

        _UnityViewControllerBaseFileContent = _UnityViewControllerBaseFileContent.Replace(_OldTextInFile, _NewTextToReplace);
        File.WriteAllText(_UnityViewControllerBaseFile, _UnityViewControllerBaseFileContent);
    }
Пример #16
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

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

            string target = proj.TargetGuidByName("Unity-iPhone");

            proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");

            File.WriteAllText(projPath, proj.WriteToString());



            // Add url schema to plist file
            string        plistPath = path + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            // Get root
            PlistElementDict rootDict = plist.root;
            rootDict.SetBoolean("UIRequiresFullScreen", true);
            plist.WriteToFile(plistPath);
        }
    }
    public static void onPostProcessBuild(BuildTarget target, string targetPath)
    {
        if (target != BuildTarget.iOS)
        {
            Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
            return;
        }
        //拉取配置文件中的数据
        MOBXCodeEditorModel xcodeModel = new  MOBXCodeEditorModel();

        xcodeModel.LoadMobpds();
        //导入文件
        PBXProject xcodeProj     = new PBXProject();
        string     xcodeProjPath = targetPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        xcodeProj.ReadFromFile(xcodeProjPath);
        //xcode Target
        string xcodeTargetGuid = xcodeProj.TargetGuidByName("Unity-iPhone");


        //plist路径targetPath
        string        plistPath     = targetPath + "/Info.plist";
        PlistDocument plistDocument = new PlistDocument();

        plistDocument.ReadFromFile(plistPath);
        PlistElementDict plistElements = plistDocument.root.AsDict();

        //添加 MOBAppkey MOBAppSecret
        AddAPPKey(plistElements);
        //添加权限 等
        AddPermissions(xcodeModel, plistElements);
        //添加白名单
        AddLSApplicationQueriesSchemes(xcodeModel, plistElements);
        //添加 URLSchemes
        AddURLSchemes(xcodeModel, plistElements);
        //添加 InfoPlistSet
        AddInfoPlistSet(xcodeModel, plistElements);
        //写入 info.plist
        plistDocument.WriteToFile(plistPath);

        //添加 BuildSettings
        AddBuildSettings(xcodeModel, xcodeProj, xcodeTargetGuid);

        //根据配置文件加载资源及xcode设置
        bool hasMobFramework = false;

        foreach (MOBPathModel pathModel in xcodeModel.folders)
        {
            AddFramework(pathModel.filePath, targetPath, xcodeTargetGuid, pathModel, xcodeProj, ref hasMobFramework);
            AddStaticLibrary(pathModel.filePath, targetPath, xcodeTargetGuid, pathModel, xcodeProj);
            AddHeader(pathModel.filePath, targetPath, xcodeTargetGuid, pathModel, xcodeProj);
            AddBundle(pathModel.filePath, targetPath, xcodeTargetGuid, pathModel, xcodeProj);
            AddOtherFile(pathModel.filePath, targetPath, xcodeTargetGuid, pathModel, xcodeProj, xcodeModel.fileFlags);
        }
        //加入系统Framework
        AddSysFrameworks(xcodeModel, xcodeProj, xcodeTargetGuid, targetPath);
        //加入 xcodeModel.frameworks 中指定的 framework
        AddXcodeModelFrameworks(xcodeModel, xcodeProj, xcodeTargetGuid, targetPath);
        xcodeProj.WriteToFile(xcodeProjPath);
    }
Пример #18
0
        protected override void Process(BuildTarget buildTarget, string buildPath)
        {
            string entitlementPath = buildPath + entitlementsPath; //Path.Combine(buildPath, entitlementsPath);

            PlistDocument entitlements = new PlistDocument();

            if (File.Exists(entitlementPath))
            {
                entitlements.ReadFromFile(entitlementPath);
            }
            else
            {
                entitlements.Create();
            }

            PlistElementArray elementArray = new PlistElementArray();

            entitlements.root["com.apple.security.application-groups"] = elementArray;
            foreach (string appGroup in appGroups)
            {
                elementArray.values.Add(new PlistElementString(appGroup));
            }

            entitlements.WriteToFile(entitlementPath);
        }
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        string path  = Path.Combine(pathToBuiltProject, "Info.plist");
        var    plist = new PlistDocument();

        plist.ReadFromFile(path);

        PlistElementArray schemes = plist.root["LSApplicationQueriesSchemes"] as PlistElementArray;

        if (schemes == null)
        {
            schemes = plist.root.CreateArray("LSApplicationQueriesSchemes");
        }
        string[] scheveValues = schemes.values.Select(e => (e as PlistElementString).value).ToArray();
        if (!scheveValues.Contains("line"))
        {
            schemes.AddString("line");
        }
        if (!scheveValues.Contains("instagram"))
        {
            schemes.AddString("instagram");
        }
        plist.WriteToFile(path);
    }
    public static void ChangeXCodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        const string iPadOrientations = "UISupportedInterfaceOrientations~ipad";

        Debug.Log("build target: " + buildTarget);
        Debug.Log("path: " + pathToBuiltProject);
        if (buildTarget == BuildTarget.iOS)
        {
            string        plistPath = pathToBuiltProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            PlistElementDict root = plist.root;

            if (iosExtraProperties.iPadLandscapeEnable)
            {
                Debug.Log("Adding landscape for iPad");
                PlistElementArray arr = new PlistElementArray();
                arr.AddString("UIInterfaceOrientationPortrait");
                arr.AddString("UIInterfaceOrientationPortraitUpsideDown");
                arr.AddString("UIInterfaceOrientationLandscapeLeft");
                arr.AddString("UIInterfaceOrientationLandscapeRight");
                root[iPadOrientations] = arr;
            }
            else
            {
                Debug.Log("removing iPad entries...");
                root[iPadOrientations] = null;
            }
            plist.WriteToFile(plistPath);
        }
    }
Пример #21
0
        private void CreateIPAExportOptionsPlist()
        {
            var           ios   = Module.UserConfig.Json.PlayerSettings.IOS;
            var           eo    = ios.IPAExportOptions;
            PlistDocument plist = new PlistDocument();

            plist.root = new PlistElementDict();
            plist.root.SetBoolean("compileBitcode", eo.CompileBitcode);
            plist.root.SetString("destination", eo.Destination);
            plist.root.SetString("method", eo.Method);
            var provisioningProfiles = plist.root.CreateDict("provisioningProfiles");

            provisioningProfiles.SetString(ios.BundleID, ios.ProfileID);
            plist.root.SetString("signingCertificate", eo.SigningCertificate);
            plist.root.SetString("signingStyle", eo.SigningStyle);
            plist.root.SetBoolean("stripSwiftSymbols", eo.StripSwiftSymbols);
            plist.root.SetString("teamID", ios.TeamID);
            plist.root.SetString("thinning", eo.Thinning);

            string tagsPath      = Path.Combine(Module.ModuleConfig.WorkPath, EBPUtility.GetTagStr(Module.ModuleStateConfig.Json.CurrentTag));
            string ipaFolderPath = Path.Combine(tagsPath, "IPA");

            Directory.CreateDirectory(ipaFolderPath);
            plist.WriteToFile(Path.Combine(ipaFolderPath, "ExportOptions.plist"));
        }
Пример #22
0
        private static void Setup_XCodePlist(string strXCodeProjectPath)
        {
            Debug.Log($"{const_strPrefix_ForDebugLog} {nameof(Setup_XCodePlist)} Start - {nameof(strXCodeProjectPath)} : {strXCodeProjectPath}");

            // Property List(.plist) Default Name
            const string strInfoPlistName = "Info.plist";

#if UNITY_IOS
            var str_plistPath   = Path.Combine(strXCodeProjectPath, strInfoPlistName);
            var p_plistDocument = new PlistDocument();
            p_plistDocument.ReadFromFile(str_plistPath);

            // Add URL Scheme
            // var array = plist.root.CreateArray("CFBundleURLTypes");
            // var urlDict = array.AddDict();
            // urlDict.SetString("CFBundleURLName", "hogehogeName");
            // var urlInnerArray = urlDict.CreateArray("CFBundleURLSchemes");
            // urlInnerArray.AddString("hogehogeValue");

            string exitsOnSuspendKey = "UIApplicationExitsOnSuspend";
            var    rootValues        = p_plistDocument.root.values;
            if (rootValues.ContainsKey(exitsOnSuspendKey))
            {
                rootValues.Remove(exitsOnSuspendKey);
            }

            // Apply editing settings to Info.plist
            p_plistDocument.WriteToFile(str_plistPath);
            Debug.Log($"{const_strPrefix_ForDebugLog} {nameof(Setup_XCodePlist)} - WriteToFile {str_plistPath}");
#else
            Debug.Log($"{const_strPrefix_ForDebugLog} {nameof(Setup_XCodePlist)} - Not Define Symbol is Not IOS");
#endif
        }
Пример #23
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);
            }
        }
Пример #24
0
        public static void AddQuickActionsToPlist(BuildTarget buildTarget, string pathToBuiltProject)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            string plistPath = pathToBuiltProject + "/Info.plist";
            var    plist     = new PlistDocument();

            plist.ReadFromFile(plistPath);

            var rootDict = plist.root;

            var quickActions = rootDict.CreateArray("UIApplicationShortcutItems");
            var singlePlayer = quickActions.AddDict();

            singlePlayer.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypePlay");
            singlePlayer.SetString("UIApplicationShortcutItemTitle", "Single Player");
            singlePlayer.SetString("UIApplicationShortcutItemType", "Singleplayer");

            var multiPlayer = quickActions.AddDict();

            multiPlayer.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypeContact");
            multiPlayer.SetString("UIApplicationShortcutItemTitle", "Online Game");
            multiPlayer.SetString("UIApplicationShortcutItemType", "Multiplayer");

            plist.WriteToFile(plistPath);
        }
Пример #25
0
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target == BuildTarget.iOS)
        {
            // Read.
            string     projectPath = PBXProject.GetPBXProjectPath(path);
            PBXProject project     = new PBXProject();
            project.ReadFromString(File.ReadAllText(projectPath));
#if UNITY_2019_3_OR_NEWER
            string targetGUID = project.GetUnityMainTargetGuid();
#else
            string targetName = PBXProject.GetUnityTargetName();
            string targetGUID = project.TargetGuidByName(targetName);
#endif
            AddFrameworks(project, targetGUID);

            var plistPath = Path.Combine(path, "Info.plist");
            var plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            plist.root.SetString("NSSpeechRecognitionUsageDescription", "This app needs access to Speech Recognition");
            plist.WriteToFile(plistPath);

            // Write.
            File.WriteAllText(projectPath, project.WriteToString());
        }
    }
        public static void AddAlwaysAndWhenInUseUsageDescriptionIfNeeded(BuildTarget buildTarget, string pathToBuiltProject)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            var plistPath = string.Format("{0}/Info.plist", pathToBuiltProject);

            var plist = new PlistDocument();

            plist.ReadFromFile(plistPath);

            var root = plist.root;

            var whenInUseUsageDescription          = root["NSLocationWhenInUseUsageDescription"]?.AsString() ?? "";
            var alwaysAndwhenInUseUsageDescription = root["NSLocationAlwaysAndWhenInUseUsageDescription"]?.AsString() ?? "";

            if (!String.IsNullOrEmpty(whenInUseUsageDescription) && String.IsNullOrEmpty(alwaysAndwhenInUseUsageDescription))
            {
                root["NSLocationAlwaysAndWhenInUseUsageDescription"] = root["NSLocationWhenInUseUsageDescription"];
            }

            plist.WriteToFile(plistPath);
        }
Пример #27
0
        /// <summary>
        /// ApplicationQueriesSchemes
        /// </summary>
        public static void SetApplicationQueriesSchemes(string buildPath, List <string> _applicationQueriesSchemes)
        {
            PlistDocument plist = GetInfoPlist(buildPath);

            //LSApplicationQueriesSchemes 白名单
            PlistElementArray queriesSchemes;

            if (plist.root.values.ContainsKey(XcodeProjectConst.APPLICATION_QUERIES_SCHEMES_KEY))
            {
                queriesSchemes = plist.root[XcodeProjectConst.APPLICATION_QUERIES_SCHEMES_KEY].AsArray();
            }
            else
            {
                queriesSchemes = plist.root.CreateArray(XcodeProjectConst.APPLICATION_QUERIES_SCHEMES_KEY);
            }

            foreach (string queriesScheme in _applicationQueriesSchemes)
            {
                if (!queriesSchemes.values.Contains(new PlistElementString(queriesScheme)))
                {
                    queriesSchemes.AddString(queriesScheme);
                }
            }

            plist.WriteToFile(GetInfoPlistPath(buildPath));
        }
Пример #28
0
    public static void OnPostprocessBuild(BuildTarget target, string buildPath)
    {
        Debug.Log(buildPath);
        if (target == BuildTarget.iOS)
        {
#if UNITY_IOS
            /*
             * string projPath = PBXProject.GetPBXProjectPath(buildPath);
             * PBXProject proj = new PBXProject();
             * proj.ReadFromFile(projPath);
             *
             * string mainTarget = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
             *
             * string newTarget = proj.AddAppExtension(mainTarget, "appext", "com.unity3d.product.appext", "appext/Info.plist");
             * proj.AddFileToBuild(newTarget, proj.AddFile(buildPath + "/appext/TodayViewController.h", "appext/TodayViewController.h"));
             * proj.AddFileToBuild(newTarget, proj.AddFile(buildPath + "/appext/TodayViewController.m", "appext/TodayViewController.m"));
             * proj.AddFrameworkToProject(newTarget, "NotificationCenter.framework", true);
             * proj.WriteToFile(projPath);
             */
            var           plistFile = Path.Combine(buildPath, "Info.plist");
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromFile(plistFile);
            plist.root["UIFileSharingEnabled"] = new PlistElementBoolean(true);
            plist.WriteToFile(plistFile);
#endif
        }
    }
Пример #29
0
    public void OnPostprocessBuild(BuildTarget target, string path)
    {
#if UNITY_EDITOR_OSX
        var buildTarget = target;
        var buildPath   = path;
#endif
#endif
#if UNITY_EDITOR_OSX
        if (buildTarget == BuildTarget.iOS)
        {
            var pbxProject     = new PBXProject();
            var pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath);
            pbxProject.ReadFromFile(pbxProjectPath);
            var targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
            pbxProject.AddFrameworkToProject(targetGuid, "libz.dylib", true);
            pbxProject.AddFrameworkToProject(targetGuid, "libz.tbd", true);
            pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
            pbxProject.WriteToFile(pbxProjectPath);
            if (_iosFileSharingEnabled)
            {
                var plistPath = buildPath + "/info.plist";
                var plist     = new PlistDocument();
                plist.ReadFromFile(plistPath);
                var dict = plist.root.AsDict();
                dict.SetBoolean("UIFileSharingEnabled", true);
                plist.WriteToFile(plistPath);
            }
        }
#endif
    }
        private static void AddNFCCapability(string path)
        {
            string projectPath = PBXProject.GetPBXProjectPath(path);
            //PBXProject project = new PBXProject();
            //project.ReadFromFile(projectPath);

            String packageName         = UnityEngine.Application.identifier;
            String name                = packageName.Substring(packageName.LastIndexOf('.') + 1);
            String entitlementFileName = name + ".entitlements";
            String entitlementPath     = Path.Combine(path, entitlementFileName);
            ProjectCapabilityManager projectCapabilityManager = new ProjectCapabilityManager(projectPath, entitlementFileName, PBXProject.GetUnityTargetName());
            PlistDocument            entitlementDocument      = AddNFCEntitlement(projectCapabilityManager);

            entitlementDocument.WriteToFile(entitlementPath);

            var        projectInfo = projectCapabilityManager.GetType().GetField("project", BindingFlags.NonPublic | BindingFlags.Instance);
            PBXProject project     = (PBXProject)projectInfo.GetValue(projectCapabilityManager);

            string            target        = project.TargetGuidByName(PBXProject.GetUnityTargetName());
            var               constructor   = typeof(PBXCapabilityType).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(bool), typeof(string), typeof(bool) }, null);
            PBXCapabilityType nfcCapability = (PBXCapabilityType)constructor.Invoke(new object[] { "com.apple.NearFieldCommunicationTagReading", true, "", false });

            project.AddCapability(target, nfcCapability, entitlementFileName);

            projectCapabilityManager.WriteToFile();
        }