public static void OnPostProcessBuild(BuildTarget target2, string path)
    {
#if UNITY_5 || UNITY_5_3_OR_NEWER
        if (target2 == BuildTarget.iOS)
#else
        if (target2 == BuildTarget.iPhone)
#endif
        {
            UnityEditor.XCodeEditor.XCProject proj = new UnityEditor.XCodeEditor.XCProject(path);

            string   projmodsPath = System.IO.Path.Combine(Application.dataPath, "SDKPackage/PSSDK/Plugins/IOS/PostProcessBuild");
            string[] projmods     = System.IO.Directory.GetFiles(projmodsPath, "PSSDK.projmods", System.IO.SearchOption.AllDirectories);

            if (projmods.Length == 0)
            {
                Debug.LogWarning("[PSSDKPostBuild] PSSDK.projmods not found!");
            }
            foreach (string p in projmods)
            {
                proj.ApplyMod(p);
            }

            proj.AddOtherLinkerFlags("-ObjC");
            //proj.AddOtherLinkerFlags ("-fobjc-arc");
            proj.Save();

            // add info.plist
            string infoPlistPath = Path.Combine(Path.GetFullPath(path), "info.plist");
            var    plist         = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(infoPlistPath));
            PlistElementDict root = plist.root;

            // NSAppTransportSecurity
            root.CreateDict("NSAppTransportSecurity").SetBoolean("NSAllowsArbitraryLoads", true);

            // Version
            PlistElementDict versionDict = (PlistElementDict)root["PackageSDKVersion"];
            if (versionDict == null)
            {
                versionDict = root.CreateDict("PackageSDKVersion");
            }

            PlistElementDict sdkVersionDict = versionDict.CreateDict("PSSDK");

            string iOS_SDK_Version       = PSSDKApi.iOS_SDK_Version;
            string Android_SDK_Version   = PSSDKApi.Android_SDK_Version;
            string Unity_Package_Version = PSSDKApi.Unity_Package_Version;


            sdkVersionDict.SetString("PSSDK_iOS_SDK_Version", iOS_SDK_Version);
            sdkVersionDict.SetString("PSSDK_Android_SDK_Version", Android_SDK_Version);
            sdkVersionDict.SetString("PSSDK_Unity_Package_Version", Unity_Package_Version);

            File.WriteAllText(infoPlistPath, plist.WriteToString());
        }
    }
    /// <summary>
    /// 設定UIRequiresFullScreen
    /// </summary>
    protected void SetRequireFullScreen()
    {
        Debug.Log("Start SetRequireFullScreen");
        PlistDocument    aPDoc     = GetProjectPlist();
        PlistElementDict aRootDict = aPDoc.root;

        aRootDict.SetBoolean("UIRequiresFullScreen", true);

        File.WriteAllText(mInfoPlistFullPath, aPDoc.WriteToString());
    }
Esempio n. 3
0
        private void ChangeEntitlementAssociatedDomains(string entitlementFilePath, AppLinkingConfiguration configuration)
        {
            PlistDocument entitlementFile = new PlistDocument();

            entitlementFile.ReadFromString(File.ReadAllText(entitlementFilePath));

            PlistElementDict rootElement = entitlementFile.root;


            var mtarget = _target == BuildTarget.iOS ? SupportedPlatforms.iOS : SupportedPlatforms.tvOS;

            var configs = configuration.GetPlatformDomainProtocols(mtarget, true).Select(d => d.Host)
                          .Distinct().ToArray();

            if (configs.Length != 0)
            {
                var associatedDomainsArrayElement = rootElement[AssociatedDomainsKey] as PlistElementArray;

                var alreadySetupDomains = new string[0];
                if (associatedDomainsArrayElement == null)
                {
                    associatedDomainsArrayElement = rootElement.CreateArray(AssociatedDomainsKey);
                }
                else
                {
                    try
                    {
                        alreadySetupDomains = associatedDomainsArrayElement.values.Select(a => a.AsString()).ToArray();
                    }
                    catch (Exception e)
                    {
                    }
                }



                //
                //  The except removes any config when the Append is used in the generation
                //
                foreach (var domainProtocol in configs.Where(c => alreadySetupDomains.Any(d => d.Contains(c)) == false))
                {
                    associatedDomainsArrayElement.AddString(AppLinksKey + domainProtocol);
                }
            }
            else
            {
                if (rootElement.values.ContainsKey(AssociatedDomainsKey))
                {
                    rootElement.values.Remove(AssociatedDomainsKey);
                }
            }


            File.WriteAllText(entitlementFilePath, entitlementFile.WriteToString());
        }
        static void ModifyPlist(string path)
        {
            // Info.plist
            string        plistPath = path + "/Info.plist";
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(path: plistPath));

            // ROOT
            PlistElementDict  rootDict = plist.root;
            PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");

            // Add URLScheme For Wechat
            PlistElementDict wxUrl = urlTypes.AddDict();

            wxUrl.SetString("CFBundleTypeRole", "Editor");
            wxUrl.SetString("CFBundleURLName", "weixin");
            wxUrl.SetString("CFBundleURLSchemes", val: Config.wechatAppId);
            PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes");

            wxUrlScheme.AddString(val: Config.wechatAppId);

            // Add URLScheme For jiguang
            PlistElementDict jgUrl = urlTypes.AddDict();

            jgUrl.SetString("CFBundleTypeRole", "Editor");
            jgUrl.SetString("CFBundleURLName", "jiguang");
            jgUrl.SetString("CFBundleURLSchemes", val: "jiguang-" + Config.jgAppKey);
            PlistElementArray jgUrlScheme = jgUrl.CreateArray("CFBundleURLSchemes");

            jgUrlScheme.AddString(val: "jiguang-" + Config.jgAppKey);

            // 白名单 for wechat
            PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");

            queriesSchemes.AddString("wechat");
            queriesSchemes.AddString("weixin");
            queriesSchemes.AddString(val: Config.wechatAppId);

            // HTTP 设置
            const string     atsKey  = "NSAppTransportSecurity";
            PlistElementDict dictTmp = rootDict.CreateDict(key: atsKey);

            dictTmp.SetBoolean("NSAllowsArbitraryLoads", true);

            PlistElementArray backModes = rootDict.CreateArray("UIBackgroundModes");

            backModes.AddString("remote-notification");

            // 出口合规信息
            rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false);

            // 写入
            File.WriteAllText(path: plistPath, plist.WriteToString());
        }
Esempio n. 5
0
    private static void OnPostprocessBuildIOS(string pathToBuiltProject)
    {
        // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module
#if UNITY_IOS
        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "ARKit.framework", false);
        string target = proj.TargetGuidByName("Unity-iPhone");
        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity"));
        // Check UnityARKitPluginSettings
        UnityARKitPluginSettings ps = LoadSettings();
        string        plistPath     = Path.Combine(pathToBuiltProject, "Info.plist");
        PlistDocument plist         = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
        PlistElementDict rootDict = plist.root;
        // Get or create array to manage device capabilities
        const string      capsKey = "UIRequiredDeviceCapabilities";
        PlistElementArray capsArray;
        PlistElement      pel;
        if (rootDict.values.TryGetValue(capsKey, out pel))
        {
            capsArray = pel.AsArray();
        }
        else
        {
            capsArray = rootDict.CreateArray(capsKey);
        }
        // Remove any existing "arkit" plist entries
        const string arkitStr = "arkit";
        capsArray.values.RemoveAll(x => arkitStr.Equals(x.AsString()));
        if (ps.AppRequiresARKit)
        {
            // Add "arkit" plist entry
            capsArray.AddString(arkitStr);
        }
        File.WriteAllText(plistPath, plist.WriteToString());
        // Add or replace define for facetracking
        UpdateDefinesInFile(pathToBuiltProject + "/Classes/Preprocessor.h", new Dictionary <string, bool>()
        {
            { "ARKIT_USES_FACETRACKING", ps.m_ARKitUsesFacetracking }
        });
        string[] filesToCopy = new string[] {
        };
        for (int i = 0; i < filesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine("../PluginSource/source", filesToCopy[i]);
            var dstLocalPath = "Libraries/" + filesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }
        File.WriteAllText(projPath, proj.WriteToString());
#endif // #if UNITY_IOS
    }
    public static void OnPostprocessBuild(BuildTarget target, string buildPath)
    {
        if (!ENABLED)
        {
            return;
        }

        if (target == BuildTarget.iOS)
        {
            string pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath);
            string plistPath      = Path.Combine(buildPath, "Info.plist");

            PBXProject pbxProject = new PBXProject();
            pbxProject.ReadFromFile(pbxProjectPath);

#if UNITY_2019_3_OR_NEWER
            string targetGUID = pbxProject.GetUnityFrameworkTargetGuid();
#else
            string targetGUID = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

            // Minimum supported iOS version on Unity 2018.1 and later is 8.0
#if !UNITY_2018_1_OR_NEWER
            if (MINIMUM_TARGET_8_OR_ABOVE)
            {
#endif
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework Photos");
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices");
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework ImageIO");
#if !UNITY_2018_1_OR_NEWER
        }
        else
        {
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-weak_framework Photos");
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework AssetsLibrary");
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices");
            pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework ImageIO");
        }
#endif

            pbxProject.RemoveFrameworkFromProject(targetGUID, "Photos.framework");

            File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());

            PlistDocument plist = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            PlistElementDict rootDict = plist.root;
            rootDict.SetString("NSPhotoLibraryUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION);
            rootDict.SetString("NSPhotoLibraryAddUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION);

            File.WriteAllText(plistPath, plist.WriteToString());
        }
    }
        public static void OnPostBuild(BuildTarget buildTarget, string path)
        {
            string        plistPath = path + "/Info.plist";
            PlistDocument plist     = new PlistDocument();

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

            rootDict.SetString("NSAppleMusicUsageDescription", NativeMusicAcessHelp.Common.iOSMusicUsageDescription);
            File.WriteAllText(plistPath, plist.WriteToString());
        }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
#if UNITY_IPHONE
        if (target != BuildTarget.iOS)
        {
            return;
        }

        // tells Xcode to automatically @include frameworks

        string pbxproj       = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        string insertKeyword = "buildSettings = {";
        string foundKeyword  = "CLANG_ENABLE_MODULES";
        string modulesFlag   = "				CLANG_ENABLE_MODULES = YES;";

        List <string> lines = new List <string>();

        foreach (string str in File.ReadAllLines(pbxproj))
        {
            if (!str.Contains(foundKeyword))
            {
                lines.Add(str);
            }
            if (str.Contains(insertKeyword))
            {
                lines.Add(modulesFlag);
            }
        }

        using (File.Create(pbxproj)) {}

        foreach (string str in lines)
        {
            File.AppendAllText(pbxproj, str + Environment.NewLine);
        }

        // add necessary permissions to Plist

        string        plistPath = Path.Combine(path, "Info.plist");
        PlistDocument plist     = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));

        PlistElementDict rootDict = plist.root;
        rootDict.SetString("NSPhotoLibraryUsageDescription", "Requires access to the Photo Library");
        rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Requires access to the Photo Library");
        rootDict.SetString("NSCameraUsageDescription", "Requires access to the Camera");
        rootDict.SetString("NSContactsUsageDescription", "Requires access to Contacts");
        rootDict.SetString("NSLocationAlwaysUsageDescription", "Requires access to Location");
        rootDict.SetString("NSLocationWhenInUseUsageDescription", "Requires access to Location");
        rootDict.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", "Requires access to Location");

        File.WriteAllText(plistPath, plist.WriteToString());
#endif
    }
Esempio n. 9
0
    /// <summary>
    ///   Update the permission
    /// </summary>
    /// <param name="pListPath">path to the Info.plist file</param>
    static void UpdatePermission(string pListPath)
    {
        PlistDocument plist = new PlistDocument();

        plist.ReadFromString(File.ReadAllText(pListPath));
        PlistElementDict rootDic = plist.root;
        var micPermission        = "NSMicrophoneUsageDescription";

        rootDic.SetString(micPermission, "Voice call need to user mic");
        File.WriteAllText(pListPath, plist.WriteToString());
    }
    /// <summary>
    /// 設定相機相簿訪問到Plist上
    /// </summary>
    protected void AddDescriptionToPlist()
    {
        Debug.Log("Start AddDescriptionToPlist");
        PlistDocument    aPDoc     = GetProjectPlist();
        PlistElementDict aRootDict = aPDoc.root;

        aRootDict.SetString("NSCameraUsageDescription", "相機訪問");
        aRootDict.SetString("NSPhotoLibraryUsageDescription", "相冊訪問");

        File.WriteAllText(mInfoPlistFullPath, aPDoc.WriteToString());
    }
Esempio n. 11
0
 private static void UpdatePlist(string buildPath)
 {
             #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
     string        plistPath = Path.Combine(buildPath, "Info.plist");
     PlistDocument plist     = new PlistDocument();
     plist.ReadFromString(File.ReadAllText(plistPath));
     PlistElementDict dict = plist.root.CreateDict("NSAppTransportSecurity");
     dict.SetBoolean("NSAllowsArbitraryLoads", true);
     File.WriteAllText(plistPath, plist.WriteToString());
             #endif
 }
        private static void UpdateProjectPlist(string plistPath)
        {
            PlistDocument plist = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));

            PlistElementDict rootDict = plist.root;

            rootDict.CreateArray("UIBackgroundModes").AddString("remote-notification");

            File.WriteAllText(plistPath, plist.WriteToString());
        }
    /// <summary>
    /// 加入Plist設定:NSAppTransportSecurity
    /// </summary>
    protected void AddTransPortSSToPlist()
    {
        Debug.Log("Start AddTransPortSSToPlist");
        PlistDocument    aPDoc     = GetProjectPlist();
        PlistElementDict aRootDict = aPDoc.root;

        PlistElementDict aTransPort = aRootDict.CreateDict("NSAppTransportSecurity");

        aTransPort.SetBoolean("NSAllowsArbitraryLoads", true);

        File.WriteAllText(mInfoPlistFullPath, aPDoc.WriteToString());
    }
Esempio n. 14
0
        private string SetupInfoPlist(NPath plistTemplatePath)
        {
            var text = plistTemplatePath.ReadAllText();
            var doc  = new PlistDocument();

            doc.ReadFromString(text);
            var root = doc.root;

            root.SetString("CFBundleIdentifier", $"com.unity.{m_gameName.ToLower()}");
            root.SetString("CFBundleDisplayName", m_gameName);
            return(doc.WriteToString());
        }
    static void SetPlist(string path)
    {
        string        plistPath = path + "/Info.plist";
        PlistDocument plist     = new PlistDocument();

        plist.ReadFromString(File.ReadAllText(plistPath));

        // Information Property List
        PlistElementDict plistDict = plist.root;

        File.WriteAllText(plistPath, plist.WriteToString());
    }
Esempio n. 16
0
        public static void HandlePlist(string pathToBuiltProject, Action <PlistElementDict> action)
        {
            var plistPath = pathToBuiltProject + "/Info.plist";

            var plist = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));

            action(plist.root);

            File.WriteAllText(plistPath, plist.WriteToString());
        }
    public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            // Get plist
            string        plistPath = pathToBuiltProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            // Get root
            PlistElementDict rootDict = plist.root;

            //
            PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");
            queriesSchemes.AddString("fb");
            queriesSchemes.AddString("instagram");
            queriesSchemes.AddString("tumblr");
            queriesSchemes.AddString("twitter");

            rootDict.CreateDict("NSCalendarsUsageDescription");
            rootDict.SetString("NSCalendarsUsageDescription", "Adding events");

            rootDict.CreateDict("NSPhotoLibraryUsageDescription");
            rootDict.SetString("NSPhotoLibraryUsageDescription", "Taking selfies");

            rootDict.CreateDict("NSCameraUsageDescription");
            rootDict.SetString("NSCameraUsageDescription", "Taking selfies");

            rootDict.CreateDict("NSMotionUsageDescription");
            rootDict.SetString("NSMotionUsageDescription", "Interactive ad controls");

            rootDict.CreateDict("NSBluetoothPeripheralUsageDescription");
            rootDict.SetString("NSBluetoothPeripheralUsageDescription", "Advertisement would like to use bluetooth.");

            PlistElementArray bundleURLTypes    = rootDict.CreateArray("CFBundleURLTypes");
            PlistElementDict  bundleURLTypesDic = bundleURLTypes.AddDict();
            PlistElementArray bundleURLSchemes  = bundleURLTypesDic.CreateArray("CFBundleURLSchemes");
            bundleURLSchemes.AddString("fbYOUR-FB-ID");

            rootDict.CreateDict("FacebookAppID");
            rootDict.SetString("FacebookAppID", "YOUR-FB-ID");

            rootDict.CreateDict("FacebookDisplayName");
            rootDict.SetString("FacebookDisplayName", "Nuumbers");

            rootDict.CreateDict("AppLovinSdkKey");
            rootDict.SetString("AppLovinSdkKey", "YOUR-SDK-KEY");

            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());
        }
    }
Esempio n. 18
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget == BuildTarget.iOS)
            {
                // var projPath = PBXProject.GetPBXProjectPath(buildPath);
                var projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
                var proj     = new PBXProject();
                proj.ReadFromFile(projPath);

                string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

                //// Configure build settings
                proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
                proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/LoomSDK/ios/LoomSDKSwift-Bridging-Header.h");
                proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "LoomSDKSwift.h");
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Libraries/LoomSDK/Frameworks");
                proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "3.0");

                //frameworks
                DirectoryInfo projectParent     = Directory.GetParent(Application.dataPath);
                char          divider           = Path.DirectorySeparatorChar;
                DirectoryInfo destinationFolder =
                    new DirectoryInfo(buildPath + divider + "Frameworks/LoomSDK/Frameworks");

                foreach (DirectoryInfo file in destinationFolder.GetDirectories())
                {
                    string filePath = "Frameworks/LoomSDK/Frameworks/" + file.Name;
                    //proj.AddFile(filePath, filePath, PBXSourceTree.Source);
                    string fileGuid = proj.AddFile(filePath, filePath, PBXSourceTree.Source);
                    proj.AddFrameworkToProject(targetGuid, file.Name, false);

                    PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
                }
                proj.WriteToFile(projPath);

                //info.plist
                var plistPath = buildPath + "/Info.plist";
                var plist     = new PlistDocument();
                plist.ReadFromFile(plistPath);
                // Update value
                PlistElementDict rootDict = plist.root;
                //rootDict.SetString("CFBundleIdentifier","$(PRODUCT_BUNDLE_IDENTIFIER)");
                PlistElementArray urls   = rootDict.CreateArray("CFBundleURLTypes");
                PlistElementDict  dic    = urls.AddDict();
                PlistElementArray scheme = dic.CreateArray("CFBundleURLSchemes");
                scheme.AddString(PlayerSettings.applicationIdentifier);
                dic.SetString("CFBundleURLName", "auth0");
                // Write plist
                File.WriteAllText(plistPath, plist.WriteToString());
            }
        }
Esempio n. 19
0
    [PostProcessBuild(10)]     // We should try to run last
    public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
                #if UNITY_IPHONE
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        string _projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject _project = new PBXProject();
        _project.ReadFromFile(_projectPath);

        string _target = _project.TargetGuidByName("Unity-iPhone");

        _project.SetBuildProperty(_target, "ENABLE_BITCODE", "NO");
        _project.SetBuildProperty(_target, "CLANG_ENABLE_MODULES", "YES");

        _project.AddCapability(_target, PBXCapabilityType.InAppPurchase);
        _project.AddCapability(_target, PBXCapabilityType.PushNotifications);

        _project.WriteToFile(_projectPath);

        UnityEngine.Debug.Log("iOSPostProcessor: Disable BITCODE");
        UnityEngine.Debug.Log("iOSPostProcessor: Enable CLANG MODULES");

        // Get plist
        string        plistPath = buildPath + "/Info.plist";
        PlistDocument plist     = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));

        // Get root
        PlistElementDict rootDict = plist.root;

        // Change value of CFBundleVersion in Xcode plist
        var buildKey = "UIBackgroundModes";
        rootDict.CreateArray(buildKey).AddString("remote-notification");

        UnityEngine.Debug.Log("iOSPostProcessor: Enable background modes: remote-notification");

        rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false);

        UnityEngine.Debug.Log("iOSPostProcessor: Set Export compliance status");

        rootDict.SetString("NSCalendarsUsageDescription", "App using calendar");

        UnityEngine.Debug.Log("iOSPostProcessor: Set NSCalendarsUsageDescription");

        // Write to file
        File.WriteAllText(plistPath, plist.WriteToString());
                #endif
    }
Esempio n. 20
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        // Replace with your iOS AdMob app ID. Your AdMob App ID will look
        // similar to this sample ID: ca-app-pub-3940256099942544~1458002511
        string appId = "ADMOB_APPLICATION_ID";

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

        plist.ReadFromFile(plistPath);
        plist.root.SetString("GADApplicationIdentifier", appId);
        File.WriteAllText(plistPath, plist.WriteToString());
    }
        private static void AddNFCReaderUsageDescription(string path)
        {
            string        plistPath = path + "/Info.plist";
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));

            PlistElementDict rootDict = plist.root;

            rootDict.SetString("NFCReaderUsageDescription", "Reading NFC Tags");

            File.WriteAllText(plistPath, plist.WriteToString());
        }
    /// <summary>
    /// Add params to Info.plist
    /// </summary>
    /// <param name="path">Path to folder</param>
    private static void FixPlist(string path)
    {
        string        plistPath = path + "/Info.plist";
        PlistDocument plist     = new PlistDocument();

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

        rootDict.SetString("NSPhotoLibraryUsageDescription", "$(PRODUCT_NAME) need to access the library in order to select photo");
        rootDict.SetString("NSCameraUsageDescription", "$(PRODUCT_NAME) need to access the camera in order to capture photo");
        File.WriteAllText(plistPath, plist.WriteToString());
        Debug.Log("Plist fixed");
    }
    /// <summary>
    /// 設定GameKit到Plist上
    /// </summary>
    protected void AddGameKitToPlist()
    {
        Debug.Log("Start AddGameKitToPlist");
        PlistDocument    aPDoc     = GetProjectPlist();
        PlistElementDict aRootDict = aPDoc.root;

        PlistElementArray aDeviceCapArray = aRootDict.CreateArray("UIRequiredDeviceCapabilities");

        aDeviceCapArray.AddString("armv7");
        aDeviceCapArray.AddString("gamekit");

        File.WriteAllText(mInfoPlistFullPath, aPDoc.WriteToString());
    }
Esempio n. 24
0
        private static void UpdateProjectPlist(BuildTarget buildTarget, string plistPath)
        {
#if UNITY_IOS
            PlistDocument plist = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));


            // NO special plist modifications in this version


            File.WriteAllText(plistPath, plist.WriteToString());
#endif
        }
    private static void SetPListProperties(string pathToBuiltProject)
    {
        var plistPath = pathToBuiltProject + "/Info.plist";
        var plist     = new PlistDocument();

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

        foreach (TDNetwork network in TDNetwork.AllNetworks)
        {
            if (network.name == "AdColony" && network.iOSEnabled)
            {
                rootDict.SetString("NSMotionUsageDescription", "Some ad content may require access to accelerometer for interactive ad experience.");
                rootDict.SetString("NSPhotoLibraryUsageDescription", "Some ad content may require access to the photo library.");
                rootDict.SetString("NSCalendarsUsageDescription", "Some ad content may create a calendar event.");
                rootDict.SetString("NSCameraUsageDescription", "Some ad content may access camera to take picture.");
            }
        }

        var transportSecurityKey = "NSAppTransportSecurity";

        if (rootDict [transportSecurityKey] == null)
        {
            rootDict.CreateDict(transportSecurityKey);
        }

        var appTransportSecurity = rootDict [transportSecurityKey].AsDict();

        appTransportSecurity.SetBoolean("NSAllowsArbitraryLoads", true);

        if (TDSettings.getInstance().admob_appid_ios.Length > 0)
        {
            rootDict.SetString("GADApplicationIdentifier", TDSettings.getInstance().admob_appid_ios);
        }

        //SKAdNetworkIds
        List <TDKeyValuePair> skAdNetworkIds = TDSettings.getInstance().skAdNetworkIds;

        if (skAdNetworkIds.Count > 0)
        {
            PlistElementArray skAdNetworkItemsArray = rootDict.CreateArray("SKAdNetworkItems");
            foreach (TDKeyValuePair pair in skAdNetworkIds)
            {
                PlistElementDict itemDict = skAdNetworkItemsArray.AddDict();
                itemDict.SetString("SKAdNetworkIdentifier", pair.getValue());
            }
        }

        // Write to file
        File.WriteAllText(plistPath, plist.WriteToString());
    }
Esempio n. 26
0
        static void ChangePlist(string pathToBuildProject)
        {
            string        path = string.Format("{0}/Info.plist", pathToBuildProject);
            PlistDocument doc  = new PlistDocument();

            doc.ReadFromString(File.ReadAllText(path));
            PlistElementDict root = doc.root;

            // 对iOS9的影响
            {
                PlistElementDict security = root.CreateDict("NSAppTransportSecurity");
                security.SetBoolean("NSAllowsArbitraryLoads", true);
            }

            // 合规证明
            {
                root.SetBoolean("ITSAppUsesNonExemptEncryption", false);
            }

            // 添加Scheme白名单
            {
                PlistElementArray schemes = root.CreateArray("LSApplicationQueriesSchemes");
                schemes.AddString("fbapi");
                schemes.AddString("fbauth2");
                schemes.AddString("fb-messenger-api");
            }

            // fb
            {
                string idFacebook = "212915212149962";

                root.SetString("FacebookAppID", idFacebook);
                root.SetString("FacebookDisplayName", PlayerSettings.productName);

                PlistElementArray types = root.CreateArray("CFBundleURLTypes");

                PlistElementDict dict = types.AddDict();
                dict.SetString("CFBundleTypeRole", "Editor");

                PlistElementArray schemes = dict.CreateArray("CFBundleURLSchemes");
                schemes.AddString("fb" + idFacebook);
            }

            // 权限
            {
                root.SetString("NSPhotoLibraryUsageDescription", "使用相册");
                root.SetString("NSCameraUsageDescription", "使用相机");
            }

            File.WriteAllText(path, doc.WriteToString());
        }
Esempio n. 27
0
    private static void AddCapabilitiesFieldToInfoPlist(string pathToBuildProject, string key, string value, PlistElement type)
    {
        string plistFilePath = Path.Combine(pathToBuildProject, "Info.plist");

        if (File.Exists(plistFilePath) == false)
        {
            return;
        }
        if (key.Length < 1 || value.Length < 1)
        {
            return;
        }

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistFilePath);
        PlistElementDict rootDic = plist.root;

        if (rootDic.values.ContainsKey(key) == false)
        {
            if (type is PlistElementString)
            {
                rootDic.SetString(key, value);
            }
            else if (type is PlistElementArray)
            {
                rootDic.CreateArray(key).AddString(value);
            }
        }
        else
        {
            if (type is PlistElementString)
            {
                rootDic.SetString(key, value);
            }
            else if (type is PlistElementArray)
            {
                PlistElementArray array = rootDic.values[key].AsArray();
                foreach (PlistElement item in array.values)
                {
                    if (item.AsString() == value)
                    {
                        Debug.LogWarningFormat("alread exist {0}:{1} in Info.plist", key, value);
                        return;
                    }
                }
                array.AddString(value);
            }
        }
        File.WriteAllText(plistFilePath, plist.WriteToString());
    }
Esempio n. 28
0
        public void CanWriteRealKey()
        {
            var doc = new PlistDocument();

            doc.Create();
            doc.root.SetReal("test", 12.1234f);
            string expected = GetPlistDataFromContents(
                @"  <dict>
    <key>test</key>
    <real>12.1234</real>
  </dict>");

            Assert.AreEqual(expected, doc.WriteToString());
        }
        private string SetupInfoPlist(NPath plistTemplatePath)
        {
            var text = plistTemplatePath.ReadAllText();
            var doc  = new PlistDocument();

            doc.ReadFromString(text);
            var root = doc.root;

            root.SetString("CFBundleIdentifier", IOSAppToolchain.Config.Identifier.PackageName);
            root.SetString("CFBundleDisplayName", IOSAppToolchain.Config.Settings.ProductName);
            var version    = IOSAppToolchain.Config.Settings.Version;
            var fieldCount = version.Revision > 0 ? 4 : 3;

            root.SetString("CFBundleShortVersionString", IOSAppToolchain.Config.Settings.Version.ToString(fieldCount));
            var buildNumber = IOSAppToolchain.Config.BuildNumber.BuildNumber;

            fieldCount = buildNumber.Build > 0 ? 3 : (buildNumber.Minor > 0 ? 2 : 1);
            root.SetString("CFBundleVersion", buildNumber.ToString(fieldCount));

            var orient      = root.CreateArray("UISupportedInterfaceOrientations");
            var orient_ipad = root.CreateArray("UISupportedInterfaceOrientations~ipad");

            foreach (var s in IOSAppToolchain.Config.GetAvailableOrientationList())
            {
                orient.AddString(s);
                orient_ipad.AddString(s);
            }

            if (BuildConfiguration.HasComponent <ARKitSettings>())
            {
                root.SetString("NSCameraUsageDescription", "Required for ARKit");

                // Get or create array to manage device capabilities
                const string capabilitiesKey = "UIRequiredDeviceCapabilities";
                var          capabilities    = root.values.TryGetValue(capabilitiesKey, out var capabilitiesValue)
                    ? capabilitiesValue.AsArray()
                    : root.CreateArray(capabilitiesKey);

                // Remove any existing "arkit" plist entries
                const string arkitEntry = "arkit";
                capabilities.values.RemoveAll(entry => entry.AsString().Equals(arkitEntry));
                if (IOSAppToolchain.Config.ARKit.Requirement == Requirement.Required)
                {
                    // Add "arkit" plist entry
                    capabilities.AddString(arkitEntry);
                }
            }

            return(doc.WriteToString());
        }
Esempio n. 30
0
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            Debug.Log("InBrainPostProcessor is now postprocessing iOS Project");

            var projectPath = PBXProject.GetPBXProjectPath(path);

            var project = new PBXProject();

            project.ReadFromFile(projectPath);

#if UNITY_2019_3_OR_NEWER
            var targetGuid = project.GetUnityFrameworkTargetGuid();
#else
            var targetName = PBXProject.GetUnityTargetName();
            var targetGuid = project.TargetGuidByName(targetName);
#endif
            project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
            project.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/Plugins/iOS/InBrainSurveys_SDK_Swift/Source/InBrainSurveys_SDK_Swift-Bridging-Header.h");
            project.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "InBrainSurveys_SDK_Swift-Swift.h");
            project.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks $(PROJECT_DIR)/lib/$(CONFIGURATION) $(inherited)");
            project.AddBuildProperty(targetGuid, "FRAMERWORK_SEARCH_PATHS", "$(inherited) $(PROJECT_DIR) $(PROJECT_DIR)/Frameworks");
            project.AddBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
            project.AddBuildProperty(targetGuid, "DYLIB_INSTALL_NAME_BASE", "@rpath");
            project.AddBuildProperty(targetGuid, "LD_DYLIB_INSTALL_NAME", "@executable_path/../Frameworks/$(EXECUTABLE_PATH)");
            project.AddBuildProperty(targetGuid, "DEFINES_MODULE", "YES");
            project.AddBuildProperty(targetGuid, "SWIFT_VERSION", "5.0");
            project.AddBuildProperty(targetGuid, "COREML_CODEGEN_LANGUAGE", "Swift");

            try
            {
                var plistInfoFile = new PlistDocument();

                var infoPlistPath = Path.Combine(path, "Info.plist");
                plistInfoFile.ReadFromString(File.ReadAllText(infoPlistPath));

                if (!plistInfoFile.root.values.ContainsKey("InBrain"))
                {
                    var inBrainDictPlist = plistInfoFile.root.CreateDict("InBrain");
                    inBrainDictPlist.SetString("client", InBrainSettings.ClientId);
                }

                File.WriteAllText(infoPlistPath, plistInfoFile.WriteToString());
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            project.WriteToFile(projectPath);
        }