/// <summary>
        /// Creates a watch extension.
        /// </summary>
        /// <returns>The GUID of the new target.</returns>
        /// <param name="proj">A project passed as this argument.</param>
        /// <param name="mainTarget">The GUID of the main target to link the watch extension to.</param>
        /// <param name="name">The name of the watch extension.</param>
        /// <param name="bundleId">The bundle ID of the watch extension. The bundle ID must be
        /// prefixed with the parent watch app bundle ID.</param>
        /// <param name="infoPlistPath">Path to the watch extension Info.plist document.</param>
        public static string AddWatchExtension(this PBXProject proj, string mainTarget,
                                               string name, string bundleId, string infoPlistPath)
        {
            var newTargetGuid = proj.AddTarget(name, ".appex", "com.apple.product-type.watchkit2-extension");

            foreach (var configName in proj.BuildConfigNames())
            {
                var configGuid = proj.BuildConfigByName(newTargetGuid, configName);
                if (configName.Contains("Debug"))
                {
                    SetDefaultWatchExtensionDebugBuildFlags(proj, configGuid);
                }
                else
                {
                    SetDefaultWatchExtensionReleaseBuildFlags(proj, configGuid);
                }
                proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
                proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath);
            }

            proj.AddSourcesBuildPhase(newTargetGuid);
            proj.AddResourcesBuildPhase(newTargetGuid);
            proj.AddFrameworksBuildPhase(newTargetGuid);

            return(newTargetGuid);
        }
Exemplo n.º 2
0
        public static string AddStickerExtension(
            this PBXProject proj,
            string mainTargetGuid,
            string name,
            string bundleId,
            string infoPlistPath)
        {
            string ext = ".appex";
            string str = proj.AddTarget(name, ext, "com.apple.product-type.app-extension.messages-sticker-pack");

            foreach (string buildConfigName in proj.BuildConfigNames())
            {
                string configGuid = proj.BuildConfigByName(str, buildConfigName);
                if (buildConfigName.Contains("Debug"))
                {
                    proj.SetDefaultAppExtensionDebugBuildFlags(configGuid);
                }
                else
                {
                    proj.SetDefaultAppExtensionReleaseBuildFlags(configGuid);
                }
                proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath);
                proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
            }
            proj.AddSourcesBuildPhase(str);
            proj.AddResourcesBuildPhase(str);
            proj.AddFrameworksBuildPhase(str);
            string sectionGuid = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed App Extensions", "", "13");

            proj.AddFileToBuildSection(mainTargetGuid, sectionGuid, proj.GetTargetProductFileRef(str));
            proj.AddTargetDependency(mainTargetGuid, str);
            return(str);
        }
Exemplo n.º 3
0
        public static string AddWatchApp(this PBXProject proj, string mainTargetGuid, string watchExtensionTargetGuid, string name, string bundleId, string infoPlistPath)
        {
            string str1 = proj.AddTarget(name, ".app", "com.apple.product-type.application.watchapp2");
            string str2 = proj.nativeTargets[watchExtensionTargetGuid].name.Replace(" ", "_");

            foreach (string name1 in proj.BuildConfigNames())
            {
                string configGuid = proj.BuildConfigByName(str1, name1);
                if (name1.Contains("Debug"))
                {
                    PBXProjectExtensions.SetDefaultWatchAppDebugBuildFlags(proj, configGuid);
                }
                else
                {
                    PBXProjectExtensions.SetDefaultWatchAppReleaseBuildFlags(proj, configGuid);
                }
                proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
                proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath);
                proj.SetBuildPropertyForConfig(configGuid, "IBSC_MODULE", str2);
            }
            proj.AddResourcesBuildPhase(str1);
            string sectionGuid1 = proj.AddCopyFilesBuildPhase(str1, "Embed App Extensions", "", "13");

            proj.AddFileToBuildSection(str1, sectionGuid1, proj.GetTargetProductFileRef(watchExtensionTargetGuid));
            string sectionGuid2 = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed Watch Content", "$(CONTENTS_FOLDER_PATH)/Watch", "16");

            proj.AddFileToBuildSection(mainTargetGuid, sectionGuid2, proj.GetTargetProductFileRef(str1));
            proj.AddTargetDependency(str1, watchExtensionTargetGuid);
            proj.AddTargetDependency(mainTargetGuid, str1);
            return(str1);
        }
Exemplo n.º 4
0
    //添加 bundle
    private static void AddBundle(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        SearchOption searchOption;

        if (secondFilePath.Contains("/ShareSDK/") || secondFilePath.Contains("\\ShareSDK\\") || secondFilePath.Contains("/ShareSDK\\")) //shareSDK
        {
            searchOption = SearchOption.TopDirectoryOnly;
        }
        else
        {
            searchOption = SearchOption.AllDirectories;
        }
        string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.bundle", searchOption);
        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            //			Debug.Log("lastFilePath" + lastFilePath);
            string bundlePath = lastFilePath.Replace(pathModel.rootPath, "");
            //			Debug.Log("bundlePath" + bundlePath);
            string savePath = xcodeTargetPath + bundlePath;
            //将 framework copy到指定目录
            DirectoryInfo bundleInfo     = new DirectoryInfo(lastFilePath);
            DirectoryInfo saveBundleInfo = new DirectoryInfo(savePath);
            CopyAll(bundleInfo, saveBundleInfo);
            //将 framework 加入 proj中
            xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddResourcesBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(bundlePath.Substring(1), "MOB" + bundlePath, PBXSourceTree.Absolute));
        }
    }
Exemplo n.º 5
0
        public void AddBuildPhasesOutputIsExpected()
        {
            ResetGuidGenerator();
            PBXProject proj   = ReadPBXProject();
            string     target = proj.AddTarget("TestTarget", ".dylib", "test.type");

            proj.AddSourcesBuildPhase(target);
            proj.AddResourcesBuildPhase(target);
            proj.AddFrameworksBuildPhase(target);
            proj.AddCopyFilesBuildPhase(target, "Copy resources", "$(DST_PATH)", "13");
            TestOutput(proj, "add_build_phases1.pbxproj");
        }
Exemplo n.º 6
0
        public void AddBuildPhasesReturnsExistingBuildPhase()
        {
            ResetGuidGenerator();
            PBXProject proj   = ReadPBXProject();
            string     target = proj.AddTarget("TestTarget", ".dylib", "test.type");

            Assert.IsNull(proj.GetSourcesBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000005", proj.AddSourcesBuildPhase(target));
            Assert.AreEqual("CCCCCCCC0000000000000005", proj.GetSourcesBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000005", proj.AddSourcesBuildPhase(target));

            Assert.IsNull(proj.GetResourcesBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000006", proj.AddResourcesBuildPhase(target));
            Assert.AreEqual("CCCCCCCC0000000000000006", proj.GetResourcesBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000006", proj.AddResourcesBuildPhase(target));

            Assert.IsNull(proj.GetFrameworksBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000007", proj.AddFrameworksBuildPhase(target));
            Assert.AreEqual("CCCCCCCC0000000000000007", proj.GetFrameworksBuildPhaseByTarget(target));
            Assert.AreEqual("CCCCCCCC0000000000000007", proj.AddFrameworksBuildPhase(target));

            Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000008", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000008", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000008", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "13"));

            // check whether all parameters are actually matched against existing phases
            Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files2", "", "13"));
            Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "path", "13"));
            Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "14"));

            Assert.AreEqual("CCCCCCCC0000000000000009", proj.AddCopyFilesBuildPhase(target, "Copy files2", "", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000009", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files2", "", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000010", proj.AddCopyFilesBuildPhase(target, "Copy files", "path", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000010", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "path", "13"));
            Assert.AreEqual("CCCCCCCC0000000000000011", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "14"));
            Assert.AreEqual("CCCCCCCC0000000000000011", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "14"));
        }
Exemplo n.º 7
0
    //添加 .h文件
    private static void AddHeader(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        string[]  secondDirectories = Directory.GetFiles(secondFilePath, "*.h", SearchOption.AllDirectories);
        ArrayList savePathArray     = new ArrayList();

        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            if (!lastFilePath.Contains(".framework"))
            {
                string headerPath = lastFilePath.Replace(pathModel.rootPath, "");

                int index = headerPath.LastIndexOf("\\");
                if (index == -1)
                {
                    index = headerPath.LastIndexOf("/");
                }
                //项目目录
                string saveHeaderPath = headerPath.Substring(0, index);
                //存放的本地目录
                string saveDirectory = xcodeTargetPath + saveHeaderPath;
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }
                //将.h copy到指定目录
                FileInfo fileInfo = new FileInfo(lastFilePath);
                string   savePath = xcodeTargetPath + headerPath;
                fileInfo.CopyTo(savePath, true);
                //将.h 加入 proj中
                xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddResourcesBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(headerPath.Substring(1), "MOB" + headerPath, PBXSourceTree.Absolute));
                if (!savePathArray.Contains(saveHeaderPath))
                {
                    savePathArray.Add(saveHeaderPath);
                    //将 build setting 设置
                    xcodeProj.AddBuildProperty(xcodeTargetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)" + saveHeaderPath.Replace("\\", "/"));
                }
            }
        }
    }