示例#1
0
    private static void updateInfoSettings(string pathToBuiltProject)
    {
        // Editing Info.plist
        var plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
        var plist     = new PlistDocument();

        plist.ReadFromFile(plistPath);

        // 设定构建版本未使用加密 <key>ITSAppUsesNonExemptEncryption</key><false/>
        plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false);

        // 列为白名单,才可正常检查其他应用是否安装
        // PlistElementArray schemes = plist.root.CreateArray("LSApplicationQueriesSchemes");
        // schemes.AddString("fbauth");
        // schemes.AddString("fb");

        /* iOS9所有的app对外http协议默认要求改成https */
        // PlistElementDict dict = plist.root.CreateDict("NSAppTransportSecurity");
        // dict.SetBoolean("NSAllowsArbitraryLoads", true);

        // 可以通过编辑器直接设置了
        // PlayerSettings.iOS.allowHTTPDownload = true;


        // 部分许可使用http
        // PlistElementDict dict = plist.root.CreateDict("NSAppTransportSecurity");
        // PlistElementDict dict2 = dict.CreateDict("NSExceptionDomains");
        // PlistElementDict dict3 = dict2.CreateDict("xxx.com");
        // dict3.SetBoolean("NSIncludesSubdomains", true);
        // dict3.SetBoolean("NSTemporaryExceptionAllowsInsecureHTTPLoads", true);
        // dict3.SetString("NSTemporaryExceptionMinimumTLSVersion", "TLSv1.1");

        // Apply editing settings to Info.plist
        plist.WriteToFile(plistPath);
    }
示例#2
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 { }
        }
    private static PlistDocument LoadPlistFromPath(string path)
    {
        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(path);
        return(plist);
    }
    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");
        }
    }
示例#5
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
#if UNITY_IPHONE || UNITY_IOS
        string        plistPath = Path.Combine(path, "Info.plist");
        PlistDocument plist     = new PlistDocument();
        plist.ReadFromFile(plistPath);

        if (GoogleMobileAdsSettings.Instance.IsAdManagerEnabled)
        {
            plist.root.SetBoolean("GADIsAdManagerApp", true);
        }

        if (GoogleMobileAdsSettings.Instance.IsAdMobEnabled)
        {
            string appId = GoogleMobileAdsSettings.Instance.AdMobIOSAppId;
            if (appId.Length == 0)
            {
                //Debug.LogError("iOS AdMob app ID is empty. Please enter a valid app ID to run ads properly.");
            }
            else
            {
                plist.root.SetString("GADApplicationIdentifier", appId);
            }
        }

        if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit)
        {
            plist.root.SetBoolean("GADDelayAppMeasurementInit", true);
        }

        File.WriteAllText(plistPath, plist.WriteToString());
#endif
    }
    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);
    }
    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);
    }
        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);
            }
        }
示例#9
0
        public static void updateInfoPlist(BuildTarget buildTarget, string buildPath)
        {
            if (!File.Exists("Assets/Appodeal/Editor/NetworkConfigs/GoogleAdMobDependencies.xml"))
            {
                Debug.Log(
                    "Can't find Google Admob Config by path - Assets/Appodeal/Editor/NetworkConfigs/GoogleAdMobDependencies.xml");
                return;
            }

            if (!CheckiOSAttribute())
            {
                Debug.LogError(
                    "Google Admob Config is invalid. Ensure that Appodeal Unity plugin is imported correctly.");
                return;
            }

            if (string.IsNullOrEmpty(AppodealSettings.Instance.AdMobIosAppId) ||
                !AppodealSettings.Instance.AdMobIosAppId.StartsWith("ca-app-pub-"))
            {
                Debug.LogError(
                    "Please enter a valid AdMob app ID within the Appodeal/AdMob settings tool.");
                return;
            }

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

            plist.ReadFromFile(plistPath);
            plist.root.SetString("GADApplicationIdentifier", AppodealSettings.Instance.AdMobIosAppId);

            File.WriteAllText(plistPath, plist.WriteToString());
        }
        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);
        }
示例#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);
    }
            public static void ChangeXcodePlist(BuildTarget buildTarget, string path)
            {
                if (buildTarget == BuildTarget.iOS)
                {
#if UNITY_IOS
                    YCConfig      ycConfig  = YCConfig.Create();
                    string        plistPath = path + "/Info.plist";
                    PlistDocument plist     = new PlistDocument();
                    plist.ReadFromFile(plistPath);
                    PlistElementDict rootDict = plist.root;

                    PlistElementArray rootCapacities = (PlistElementArray)rootDict.values["UIRequiredDeviceCapabilities"];
                    rootCapacities.values.RemoveAll((PlistElement elem) => {
                        return(elem.AsString() == "metal");
                    });

                    rootDict.SetString("NSCalendarsUsageDescription", "Used to deliver better advertising experience");
                    rootDict.SetString("NSLocationWhenInUseUsageDescription", "Used to deliver better advertising experience");
                    rootDict.SetString("NSPhotoLibraryUsageDescription", "Used to deliver better advertising experience");
                    rootDict.SetString("NSAdvertisingAttributionReportEndpoint", "https://tenjin-skan.com");
                    rootDict.values.Remove("UIApplicationExitsOnSuspend");
                    File.WriteAllText(plistPath, plist.WriteToString());
#endif
                }
            }
    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);
    }
        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);
        }
示例#15
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
        }
    }
    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
        }
    }
示例#17
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        string        plistPath = Path.Combine(path, "Info.plist");
        PlistDocument plist     = new PlistDocument();

        plist.ReadFromFile(plistPath);

        string appId = GoogleMobileAdsSettings.Instance.GoogleMobileAdsIOSAppId;

        if (appId.Length == 0)
        {
            NotifyBuildFailure(
                "iOS Google Mobile Ads app ID is empty. Please enter a valid app ID to run ads properly.");
        }
        else
        {
            plist.root.SetString("GADApplicationIdentifier", appId);
        }

        if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit)
        {
            plist.root.SetBoolean("GADDelayAppMeasurementInit", true);
        }

        List <string> skNetworkIds = ReadSKAdNetworkIdentifiersFromXML();

        if (skNetworkIds.Count > 0)
        {
            AddSKAdNetworkIdentifier(plist, skNetworkIds);
        }

        File.WriteAllText(plistPath, plist.WriteToString());
    }
示例#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);
        }
示例#19
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);
    }
示例#20
0
        static public Loader LookingForLoader(string path)
        {
            Loader        loader = null;
            PlistDocument pd     = new PlistDocument();

            pd.ReadFromFile(path);

            try
            {
                int format = pd.root["metadata"].AsDict()["format"].AsInteger();
                if (format == 2)
                {
                    loader = new Loader_Format2();
                }
                else if (format == 3)
                {
                    loader = new Loader_Format3();
                }
                else
                {
                    Debug.LogWarning("找到format,但是尚未处理");
                }
            }
            catch
            {
                Debug.LogWarning("找不到format");
            }

            return(loader);
        }
示例#21
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);
        }
    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);
        }
    }
示例#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
        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
        }
示例#25
0
    // [PostProcessBuild(40006)]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        Debug.Log("TTPPrivacySettingsPostProcess::OnPostprocessBuild");
#if CRAZY_LABS_CLIK
        Debug.Log("TTPPrivacySettingsPostProcess::OnPostprocessBuild: in CLIK");
        var includedServicesPath = "Assets/Tabtale/TTPlugins/CLIK/Resources/ttpIncludedServices.asset";
        if (File.Exists(includedServicesPath))
        {
            Debug.Log("TTPPrivacySettingsPostProcess::OnPostprocessBuild: found included services asset");
            var includedServices = AssetDatabase.LoadAssetAtPath <TTPIncludedServicesScriptableObject>(includedServicesPath);
            if (!includedServices.privacySettings)
            {
                Debug.Log("TTPPrivacySettingsPostProcess::OnPostprocessBuild: privacy settings not included");
                return;
            }
        }
#endif
        var pbxProjectPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path);
        var pbxProject     = new UnityEditor.iOS.Xcode.PBXProject();
        pbxProject.ReadFromString(System.IO.File.ReadAllText(pbxProjectPath));
        var plistPath = Path.Combine(path, "Info.plist");
        var plist     = new PlistDocument();
        plist.ReadFromFile(plistPath);
        var rootDict = plist.root;
        rootDict.SetString("NSUserTrackingUsageDescription", "If you agree our partners will use your data to show you relevant ads.\n" +
                           "To learn how we use data: https://crazylabs.com/app.\n" +
                           "Our partners who rely on your consent: https://crazylabs.com/3rdp.\n" +
                           "You can change your selection any time in the Limit Ad Tracking settings on your device.");

        File.WriteAllText(plistPath, plist.WriteToString());
    }
示例#26
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);
        }
示例#27
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);
        }
示例#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 PostProcessBuild(string path)
    {
        #region pbxproj
        string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

        // PBXProject class represents a project build settings file,
        // here is how to read that in.
        PBXProject proj = new PBXProject();
        proj.ReadFromFile(projPath);

        // This is the Xcode target in the generated project
        string target = proj.TargetGuidByName("Unity-iPhone");

        // Write PBXProject object back to the file
        //proj.AddBuildProperty(target, "ENABLE_BITCODE", "NO");

        proj.AddFrameworkToProject(target, "VideoToolbox.framework", false);
        proj.AddFrameworkToProject(target, "libz.tbd", false);
        proj.AddFrameworkToProject(target, "libbz2.tbd", false);
        proj.AddFrameworkToProject(target, "libiconv.tbd", false);

        proj.WriteToFile(projPath);
        #endregion

        #region info plist
        string plistPath = path + "/Info.plist";

        PlistDocument plist = new PlistDocument();
        plist.ReadFromFile(plistPath);
        plist.root.SetString("NSMicrophoneUsageDescription", "User can record himself and video");
        plist.WriteToFile(plistPath);
        #endregion
    }