SetApplicationQueriesSchemes() public static method

canOpenURLで判定可能にするスキームを登録する
public static SetApplicationQueriesSchemes ( string buildPath, List _applicationQueriesSchemes ) : void
buildPath string
_applicationQueriesSchemes List
return void
Exemplo n.º 1
0
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //iOS以外にビルドしている場合は更新処理を行わないように
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        //Xcodeの設定データを読み込む
        XcodeProjectSetting setting = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(SETTING_DATA_PATH);

        if (setting == null)
        {
            Debug.Log("Resources/" + SETTING_DATA_PATH + "がありません!");
            return;
        }
        //Xcodeプロジェクトの読み込み
        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //ターゲットのID取得
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        //指定ディレクトリ内のファイルを全てコピーする
        if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");
        }

        //コンパイラフラグの設定
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    Debug.Log(targetPath + "が無いのでコンパイラフラグが設定できませんでした");
                    continue;
                }

                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);

                InfoPlistProcessor.SetURLSchemes(buildPath, fileGuid, flagsList);
            }
        }

        //システムのフレームワークを追加
        foreach (string framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework, false);
        }

        foreach (string lib in setting.LibraryList)
        {
            string fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);
            pbxProject.AddFileToBuild(targetGuid, fileGuid);
        }

        //Linker Flagの設定
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);

        //フレームワークがあるディレクトリへのパス設定
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);

        //BitCodeの設定
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");

        //プロジェクトファイル書き出し
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //URLスキームの設定

        /*
         * List<string> urlSchemeList = new List<string>(setting.URLSchemeList);
         * InfoPlistProcessor.SetURLSchemes(buildPath, setting.URLIdentifier, urlSchemeList);
         */

        foreach (XcodeProjectSetting.URLIdentifierSet compilerFlagsSet in setting.URLIdentifierList)
        {
            List <string> urlSchemeList = new List <string>(compilerFlagsSet.URLSchemeList);
            InfoPlistProcessor.SetURLSchemes(buildPath, compilerFlagsSet.Flags, urlSchemeList);
        }

        List <string> applicationQueriesSchemes = new List <string>(setting.ApplicationQueriesSchemes);

        InfoPlistProcessor.SetApplicationQueriesSchemes(buildPath, applicationQueriesSchemes);

        //デフォルトで設定されているスプラッシュ画像の設定を消す
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATSの設定
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //ステータスバーの設定
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);
        var    code_path = buildPath + "/Classes/UnityAppController.h";
        string code_head = FileUtils.getInstance().getString(code_path);

        if (code_head.IndexOf("@property NSURL* mUrl;") == -1)
        {
            code_head = code_head.Replace("- (void)shouldAttachRenderDelegate;", "- (void)shouldAttachRenderDelegate;\n@property NSURL* mUrl;\n");
            FileUtils.getInstance().writeString(code_path, code_head);
        }
        code_path = buildPath + "/Classes/UnityAppController.mm";
        string code = FileUtils.getInstance().getString(code_path);

        if (code_head.IndexOf("_mUrl = url;") == -1)
        {
            code = code.Replace("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);", "_mUrl = url;\nAppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);");
            FileUtils.getInstance().writeString(code_path, code);
        }
    }
Exemplo n.º 2
0
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //是不是ios
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        string cfgPath = Application.dataPath + "/XcodeSet.asset";//PlayerPrefs.GetString(SETTING_DATA_PATHKEY,"");

        if (string.IsNullOrEmpty(cfgPath))
        {
            return;
        }
        //Xcode读取配置数据
        XcodeProjectSetting setting = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(cfgPath);

        if (setting == null)
        {
            Debug.Log("Resources/" + cfgPath + "目录不存在");
            return;
        }
        else
        {
            Debug.LogError("cfgPath =" + cfgPath);
        }

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

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //获取 target的Guid
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
        string projPath   = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        //LinkLibraries(projPath);
        //拷贝所有文件
        if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");
        }

        //设置编译器标志
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    Debug.Log(targetPath + "编译器标志不能被设置,因为没有这个标志");
                    continue;
                }

                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);

                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        //添加所有的 Framework
        foreach (string framework in setting.FrameworkList)
        {
            string libStr = framework;
            bool   weak   = false;
            if (framework.Contains(":"))
            {
                string[] ss = framework.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }
            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }

        foreach (string lib in setting.LibList)
        {
            string libStr = lib;
            bool   weak   = false;
            if (lib.Contains(":"))
            {
                string [] ss = lib.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }

            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }

        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);

        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);

        //BitCode
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");

        //保存最终工程
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        InfoPlistProcessor.SetApplicationQueriesSchemes(buildPath, setting.ApplicationQueriesSchemes);

        //URL配置
        foreach (XcodeProjectSetting.URLIdentifierData urlData in setting.URLIdentifierList)
        {
            InfoPlistProcessor.SetURLSchemes(buildPath, urlData.name, urlData.URLSchemes);
        }

        //关闭启动图像的已设定默认的设定
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATS配置
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //设置状态栏
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);

        //添加特殊的key   比如麦克风//
        foreach (XcodeProjectSetting.AddToInfoStringList data in setting.addStringKeyToPlist)
        {
            InfoPlistProcessor.AddStringKey(buildPath, data.Key, data.value);
        }

        foreach (XcodeProjectSetting.AddCodeData data in setting.AddCodeList)
        {
            string fileName = GetCClassFileName(buildPath, data.FileName);

            if (System.IO.File.Exists(fileName))
            {
                XClass xc = new XClass(fileName);
                xc.WriteStart(data.StartAddCode);
                foreach (XcodeProjectSetting.AddCodeSet addSet in data.addCodes)
                {
                    Debug.LogError(addSet.addFlag + "/需要替换的文件/" + addSet.AddCode);
                    xc.WriteBelow(addSet.addFlag, addSet.AddCode);
                }
                foreach (XcodeProjectSetting.ReplaceCodeSet replaceSet in data.replaceCode)
                {
                    xc.Replace(replaceSet.oldCode, replaceSet.newCode);
                }
            }
        }
        PlayerPrefs.DeleteKey(SETTING_DATA_PATHKEY);
    }