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());
    }
示例#2
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());
        }
示例#3
0
    private static void PatchPlist(string path, List <Unity.Notifications.NotificationSetting> settings, bool addPushNotificationCapability)
    {
        var plistPath = path + "/Info.plist";
        var plist     = new PlistDocument();

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

        var rootDict            = plist.root;
        var needsToWriteChanges = false;

        // Add all the settings to the plist.
        foreach (var setting in settings)
        {
            if (ShouldAddSettingToPlist(setting, rootDict))
            {
                needsToWriteChanges = true;
                if (setting.Value.GetType() == typeof(bool))
                {
                    rootDict.SetBoolean(setting.Key, (bool)setting.Value);
                }
                else if (setting.Value.GetType() == typeof(PresentationOption) ||
                         setting.Value.GetType() == typeof(AuthorizationOption))
                {
                    rootDict.SetInteger(setting.Key, (int)setting.Value);
                }
            }
        }

        // Add "remote-notification" to the list of supported UIBackgroundModes.
        if (addPushNotificationCapability)
        {
            PlistElementArray currentBackgroundModes = (PlistElementArray)rootDict["UIBackgroundModes"];
            if (currentBackgroundModes == null)
            {
                currentBackgroundModes = rootDict.CreateArray("UIBackgroundModes");
            }

            var remoteNotificationElement = new PlistElementString("remote-notification");
            if (!currentBackgroundModes.values.Contains(remoteNotificationElement))
            {
                currentBackgroundModes.values.Add(remoteNotificationElement);
                needsToWriteChanges = true;
            }
        }

        if (needsToWriteChanges)
        {
            File.WriteAllText(plistPath, plist.WriteToString());
        }
    }
示例#4
0
    /// <summary>
    /// 设置后台模式
    /// </summary>
    /// <param name="plist"></param>
    /// <param name="modes"></param>
    private static void SetBackgroundModes(PlistDocument plist, List <string> modes)
    {
        int count = modes.Count;

        if (count > 0)
        {
            PlistElementDict  rootDict = plist.root;
            PlistElementArray bgModes  = rootDict.CreateArray("UIBackgroundModes");
            for (int i = 0; i < count; i++)
            {
                bgModes.AddString(modes[i]);
            }
        }
    }
    private static void generatePlistFile(PlistElementDict rootDict, string path)
    {
        rootDict.SetString("CFBundleIdentifier", "com.gekko.rok");
        rootDict.SetString("CFBundleDisplayName", "Rage of Kings");
        //rootDict.SetString("CFBundleVersion", GetVer());
        rootDict.SetString("NSPhotoLibraryUsageDescription", "Use Photo");
        rootDict.SetString("NSCameraUsageDescription", "Use Camera");
        //rootDict.SetString("CFBundleShortVersionString", GKVersion.GAME_VERSION);
        rootDict.SetString("ITSAppUsesNonExemptEncryption", "false");
        rootDict.SetString("LSHasLocalizedDisplayName", "true");

        //weixin scheme
        PlistElementArray urlArray = null;

        if (!rootDict.values.ContainsKey("CFBundleURLTypes"))
        {
            urlArray = rootDict.CreateArray("CFBundleURLTypes");
        }
        else
        {
            urlArray = rootDict.values["CFBundleURLTypes"].AsArray();
        }
        var urlTypeDict = urlArray.AddDict();

        urlTypeDict.SetString("CFBundleURLName", "weixin");
        var urlScheme = urlTypeDict.CreateArray("CFBundleURLSchemes");

        urlScheme.AddString("weixin_id");

        if (!rootDict.values.ContainsKey("LSApplicationQueriesSchemes"))
        {
            urlArray = rootDict.CreateArray("LSApplicationQueriesSchemes");
        }
        else
        {
            urlArray = rootDict["LSApplicationQueriesSchemes"].AsArray();
        }
        urlArray.AddString("weixin");

        //Gamecenter
        if (rootDict.values.ContainsKey("UIRequiredDeviceCapabilities"))
        {
            rootDict.values.Remove("UIRequiredDeviceCapabilities");
        }
        var arr = rootDict.CreateArray("UIRequiredDeviceCapabilities");

        arr.AddString("armv7");
        arr.AddString("gamekit");
    }
示例#6
0
    public static void AddString(this PlistElementArray array, string key, bool isKeepUnique)
    {
        if (!isKeepUnique)
        {
            array.AddString(key);
            return;
        }
        var keys = array.values.Where(x => x.AsString() == key);

        if (keys != null && keys.Count() != 0)
        {
            return;
        }
        array.AddString(key);
    }
示例#7
0
 /// <summary>
 /// Check if the value is already contained in the plist
 /// </summary>
 internal static bool PlistContainsAdNetworkId(PlistElementArray adNetworkItems, string adNetworkId)
 {
     foreach (var adNetworkItem in adNetworkItems.values)
     {
         var item = adNetworkItem.AsDict();
         if (item.values.TryGetValue(k_SkAdNetworkIdentifier, out var value))
         {
             if (value.AsString() == adNetworkId)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        static void AddDeviceCapabilities(string pathToBuiltProject)
        {
            string        infoPlistPath = Path.Combine(pathToBuiltProject, "./Info.plist");
            PlistDocument plist         = new PlistDocument();

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

            PlistElementDict  rootDict = plist.root;
            PlistElementArray deviceCapabilityArray = rootDict.CreateArray("UIRequiredDeviceCapabilities");

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

            File.WriteAllText(infoPlistPath, plist.WriteToString());
        }
示例#9
0
        private PlistElementDict GetOrCreateUniqueDictElementInArray(PlistElementArray root)
        {
            PlistElementDict r;

            if (root.values.Count == 0)
            {
                r = root.values[0] as PlistElementDict;
            }
            else
            {
                r = new PlistElementDict();
                root.values.Add(r);
            }
            return(r);
        }
        /// <summary>
        /// Extension method for ProjectCapabilityManager to add the Sign In With Apple capability in compatibility mode.
        /// In particular, adds the AuthenticationServices.framework as an Optional framework, preventing crashes in
        /// iOS versions previous to 13.0
        /// </summary>
        /// <param name="manager">The manager for the main target to use when adding the Sign In With Apple capability.</param>
        /// <param name="unityFrameworkTargetGuid">The GUID for the UnityFramework target. If null, it will use the main target GUID.</param>
        public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityManager manager, string unityFrameworkTargetGuid = null)
        {
            var managerType        = typeof(ProjectCapabilityManager);
            var capabilityTypeType = typeof(PBXCapabilityType);

            var projectField                    = managerType.GetField("project", NonPublicInstanceBinding);
            var targetGuidField                 = managerType.GetField("m_TargetGuid", NonPublicInstanceBinding);
            var entitlementFilePathField        = managerType.GetField("m_EntitlementFilePath", NonPublicInstanceBinding);
            var getOrCreateEntitlementDocMethod = managerType.GetMethod("GetOrCreateEntitlementDoc", NonPublicInstanceBinding);
            var constructorInfo                 = capabilityTypeType.GetConstructor(
                NonPublicInstanceBinding,
                null,
                new[] { typeof(string), typeof(bool), typeof(string), typeof(bool) },
                null);

            if (projectField == null || targetGuidField == null || entitlementFilePathField == null ||
                getOrCreateEntitlementDocMethod == null || constructorInfo == null)
            {
                throw new Exception("Can't Add Sign In With Apple programatically in this Unity version");
            }

            var entitlementFilePath = entitlementFilePathField.GetValue(manager) as string;
            var entitlementDoc      = getOrCreateEntitlementDocMethod.Invoke(manager, new object[] { }) as PlistDocument;

            if (entitlementDoc != null)
            {
                var plistArray = new PlistElementArray();
                plistArray.AddString(DefaultAccessLevel);
                entitlementDoc.root[EntitlementsArrayKey] = plistArray;
            }

            var project = projectField.GetValue(manager) as PBXProject;

            if (project != null)
            {
                var mainTargetGuid = targetGuidField.GetValue(manager) as string;
                var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.developer.applesignin.custom", true, string.Empty, true }) as PBXCapabilityType;

                var targetGuidToAddFramework = unityFrameworkTargetGuid;
                if (targetGuidToAddFramework == null)
                {
                    targetGuidToAddFramework = mainTargetGuid;
                }

                project.AddFrameworkToProject(targetGuidToAddFramework, AuthenticationServicesFramework, true);
                project.AddCapability(mainTargetGuid, capabilityType, entitlementFilePath, false);
            }
        }
    public static void AddMegacoolCapabilitiesToEntitlements(string pathToFile, Uri baseUrl)
    {
        string associatedDomainsValue = "com.apple.developer.associated-domains";
        string megacoolAppLink        = "applinks:" + baseUrl.Host;

        PlistDocument plist = new PlistDocument();

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

        // Get root
        PlistElementDict  rootDict          = plist.root;
        PlistElementArray associatedDomains = null;

        //Check if com.apple.developer.associated-domains exists in plist
        if (!rootDict.values.ContainsKey(associatedDomainsValue))
        {
            associatedDomains = rootDict.CreateArray(associatedDomainsValue);
        }
        else
        {
            associatedDomains = rootDict.values[associatedDomainsValue].AsArray();

            if (associatedDomains == null)
            {
                associatedDomains = rootDict.CreateArray(associatedDomainsValue);
            }
        }

        bool megacoolAppLinkExists = false;

        foreach (PlistElement elem in associatedDomains.values)
        {
            if (elem.AsString() != null && elem.AsString().Equals(megacoolAppLink))
            {
                megacoolAppLinkExists = true;
                break;
            }
        }

        //Add applinks:mgcl.co
        if (!megacoolAppLinkExists)
        {
            associatedDomains.AddString(megacoolAppLink);
        }

        // Write to file
        File.WriteAllText(pathToFile, plist.WriteToString());
    }
示例#12
0
 //在info.plist中添加 URLSchemes
 private static void AddURLSchemes(MOBXCodeEditorModel xcodeModel,PlistElementDict plistElements)
 {
     ArrayList URLSchemes = xcodeModel.URLSchemes;
     PlistElementArray elementArray = plistElements.CreateArray ("CFBundleURLTypes");
     foreach (Hashtable scheme in URLSchemes)
     {
         PlistElementDict dict = elementArray.AddDict ();
         dict.SetString ("CFBundleURLName",(string)scheme["CFBundleURLName"]);
         PlistElementArray urlArray = dict.CreateArray ("CFBundleURLSchemes");
         ArrayList schemes = (ArrayList)scheme ["CFBundleURLSchemes"];
         foreach (string schemeStr in schemes)
         {
             urlArray.AddString (schemeStr);
         }
     }
 }
示例#13
0
    private static void SetBackgroundMode(string path)
    {
        var plistPath = Path.Combine(path, "Info.plist");

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistPath);

        plist.root.SetBoolean("FirebaseAppDelegateProxyEnabled", false);

        PlistElementArray bgModes = plist.root.CreateArray("UIBackgroundModes");

        bgModes.AddString("remote-notification");

        plist.WriteToFile(plistPath);
    }
        public static void SetiOSUrlId(string urlId, PlistElementDict rootDict)
        {

            PlistElementArray urlTypesArray =
                rootDict["CFBundleURLTypes"] != null ? rootDict["CFBundleURLTypes"].AsArray()
                                                                                   : rootDict.CreateArray("CFBundleURLTypes");


            PlistElementDict urlTypes = urlTypesArray.AddDict();

            urlTypes.SetString("CFBundleTypeRole", "Editor");
            urlTypes.SetString("CFBundleURLName", urlId);

            PlistElementArray urlSchemes = urlTypes.CreateArray("CFBundleURLSchemes");
            urlSchemes.AddString(urlId);
		}
    public static void ModifyFrameworkAndInfoList(BuildTarget BuildTarget, string path)
    {
        if (BuildTarget == BuildTarget.iOS)
        {
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));
            string xtarget = proj.TargetGuidByName("Unity-iPhone");

            // add extra framework(s)
            proj.AddFrameworkToProject(xtarget, "AssetsLibrary.framework", false);

            // set code sign identity & provisioning profile
            proj.SetBuildProperty(xtarget, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________");
            proj.SetBuildProperty(xtarget, "PROVISIONING_PROFILE", "********-****-****-****-************");

            // rewrite to file
            File.WriteAllText(projPath, proj.WriteToString());

            // 由于我的开发机是英文系统,但游戏需要设置为中文;
            // 需要在修改 Info.plist 中的 CFBundleDevelopmentRegion 字段为 zh_CN

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

            // Get root
            PlistElementDict rootDict = plist.root;

            // Change value of CFBundleDevelopmentRegion in Xcode plist
            rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN");

            PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");

            // add weixin url scheme
            PlistElementDict wxUrl = urlTypes.AddDict();
            wxUrl.SetString("CFBundleTypeRole", "Editor");
            wxUrl.SetString("CFBundleURLName", "weixin");
            PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes");
            wxUrlScheme.AddString("____________");

            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());
        }
    }
    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

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

        PlistDocument plist = new PlistDocument();
        plist.ReadFromFile(plistPath);
        #region QueriesSchemes
        PlistElementArray queriesSchemesArray = plist.root.CreateArray("LSApplicationQueriesSchemes");
        queriesSchemesArray.AddString("project");
        #endregion

        #region own URLScheme
        PlistElementArray urlTypesArray = plist.root.CreateArray("URL types");
        PlistElementDict  dict          = urlTypesArray.AddDict();
        dict.SetString("URL identifier", "com.compsany.project");
        PlistElementArray urlSchemesArray = dict.CreateArray("URL Schemes");
        urlSchemesArray.AddString("project");
        #endregion

        plist.WriteToFile(plistPath);
        #endregion
#endif
    }
        static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target == BuildTarget.iOS)
            {
#if UNITY_IOS
                string[] languagesSetupGuiIDs = AssetDatabase.FindAssets("t:LanguagesSetup");
                if (languagesSetupGuiIDs.Length < 1)
                {
                    UnityEngine.Debug.LogWarning("No Language Setup asset found, skipping populating CFBundleLocalizations");
                }
                else if (languagesSetupGuiIDs.Length > 1)
                {
                    UnityEngine.Debug.LogWarning("More than one Language Setup asset found in the project. Make sure only one is present in your Assets folder. Skipping populating CFBundleLocalizations");
                }
                else
                {
                    var            path               = AssetDatabase.GUIDToAssetPath(languagesSetupGuiIDs[0]);
                    LanguagesSetup languagesSetup     = (LanguagesSetup)AssetDatabase.LoadAssetAtPath(path, typeof(LanguagesSetup));
                    var            supportedLanguages = languagesSetup.getSupportedLanguages();

                    UnityEngine.Debug.LogFormat("Populating CFBundleLocalizations with Language Setup asset found at: {0}", path);

                    // Adding supported languages to CFBundleLocalizations in the XCode project
                    if (supportedLanguages.Length > 0)
                    {
                        var pListPath = Path.Combine(pathToBuiltProject, "Info.plist");
                        var pList     = new PlistDocument();
                        pList.ReadFromFile(pListPath);
                        var root = pList.root;

                        PlistElementArray languages = root.CreateArray("CFBundleLocalizations");
                        foreach (var l in supportedLanguages)
                        {
                            var isoCode = LanguageUtils.getISOCodeFromLanguage(l);
                            languages.AddString(isoCode);
                        }

                        pList.WriteToFile(pListPath);
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning("No languages found in current Languages Setup asset, skipping populating CFBundleLocalizations");
                    }
                }
#endif
            }
        }
        public static void OnPostProcess(BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            var dummy = CreateInstance <EntitlementsAndPlistPostProcess>();
            var file  = dummy.entitlementsFile;

            if (file == null)
            {
                Debug.LogError("EntitlementsAndPlistPostProcess::entitlementsFileMissing!");
                return;
            }

            DestroyImmediate(dummy);

#if UNITY_IOS
            var pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath);
            var pbxProject     = new PBXProject();
            pbxProject.ReadFromFile(pbxProjectPath);

            const string targetName = "Unity-iPhone";
            var          targetGuid = pbxProject.GetUnityMainTargetGuid();
            var          src        = AssetDatabase.GetAssetPath(file);
            var          fileName   = Path.GetFileName(src);
            var          dst        = buildPath + "/" + targetName + "/" + fileName;
            if (!File.Exists(dst))
            {
                FileUtil.CopyFileOrDirectory(src, dst);
            }
            pbxProject.AddFile(targetName + "/" + fileName, fileName);
            pbxProject.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", targetName + "/" + fileName);
            pbxProject.WriteToFile(pbxProjectPath);

            var plistPath     = buildPath + "/Info.plist";
            var plistDocument = new PlistDocument();
            plistDocument.ReadFromString(File.ReadAllText(plistPath));
            var rootDict = plistDocument.root;
            rootDict.SetBoolean("FirebaseAppDelegateProxyEnabled", false);
            PlistElementArray customDomains = rootDict.CreateArray("FirebaseDynamicLinksCustomDomains");
            customDomains.AddString("https://cgs.link");
            File.WriteAllText(plistPath, plistDocument.WriteToString());
#endif
        }
示例#19
0
    public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
#if UNITY_IOS
        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;

            // background location useage key (new in iOS 8)
            rootDict.SetString("NSMicrophoneUsageDescription", "Microphone Access Warning");
            rootDict.SetString("NSCameraUsageDescription", "Camera Access Warning");
            rootDict.SetString("NSPhotoLibraryUsageDescription", "Photo Library Access Warning");
            rootDict.SetString("UIBackgroundModes", "remote-notification");
            rootDict.SetString("UIRequiresFullScreen", "YES");
            rootDict.SetString("App Uses Non-Exempt Encryption", "NO");

            // background modes
            PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes");
            bgModes.AddString("remote-notification");
            //bgModes.AddString("location");
            //bgModes.AddString("fetch");

            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());

            string     projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
            PBXProject proj     = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));

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

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

            proj.AddFrameworkToProject(target, "SafariServices.framework", false /*not weak*/);

            proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");

            File.WriteAllText(projPath, proj.WriteToString());
        }
#endif
    }
示例#20
0
    static void AddToArray(PlistElementDict dict, string arrayName, string element)
    {
        if (dict[arrayName] == null)
        {
            dict.CreateArray(arrayName);
        }
        PlistElementArray a = dict[arrayName].AsArray();

        foreach (PlistElement e in a.values)
        {
            if (e.AsString() == element)
            {
                return;
            }
        }
        a.AddString(element);
    }
        public static void SetApplicationQueriesSchemes(BuildTarget buildTarget, string pathToBuiltProject)
        {
            // This is needed only for iOS
            if (buildTarget == BuildTarget.iOS)
            {
                // Map application bundle IDs with URL schemes
                Dictionary <string, string> applicationBundlesMap = new Dictionary <string, string>();
                applicationBundlesMap.Add("com.poisins.App1", "cp.app1");
                applicationBundlesMap.Add("com.poisins.App2", "cp.app2");

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

                // Get root
                PlistElementDict rootDict = plist.root;

                // Set URL schemes app is able to respond
                PlistElementArray bundleUrlTypes   = rootDict.CreateArray("CFBundleURLTypes");       // create dictionary of Types
                PlistElementDict  urlTypesDict     = bundleUrlTypes.AddDict();
                PlistElementArray bundleUrlSchemes = urlTypesDict.CreateArray("CFBundleURLSchemes"); // create URL schemes in Types dictionary

                // Set URL schemes app is allowed to query
                PlistElementArray appQuerySchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");

                // Process all schemes
                foreach (KeyValuePair <string, string> pair in applicationBundlesMap)
                {
                    // if current project, then add to CFBundleURLSchemes array
                    if (pair.Key == Application.bundleIdentifier)
                    {
                        bundleUrlSchemes.AddString(pair.Value);
                    }
                    //else LSApplicationQueriesSchemes array
                    else
                    {
                        appQuerySchemes.AddString(pair.Value);
                    }
                }

                // Write to file
                File.WriteAllText(plistPath, plist.WriteToString());
            }
        }
示例#22
0
        public static void AddRangeIfMissing(this PlistElementArray elementArray, IEnumerable <string> values)
        {
            if (elementArray is null)
            {
                throw new ArgumentNullException(nameof(elementArray));
            }

            var here = elementArray.values.OfType <PlistElementString>().Select(e => e.value);
            var set  = new HashSet <string>(here);

            foreach (var value in values)
            {
                if (set.Contains(value) == false)
                {
                    elementArray.AddString(value);
                }
            }
        }
示例#23
0
    static void EditInfoPlist(string filePath)
    {
        string path = filePath + "/Info.plist";

        PlistDocument plistDocument = new PlistDocument();

        plistDocument.ReadFromFile(path);
        PlistElementDict dict = plistDocument.root.AsDict();

        // 添加白名单(add Application Queries Schemes)
        PlistElementArray array = dict.CreateArray("LSApplicationQueriesSchemes");

        // tianmao/taobao Application Queries Schemes:
        array.AddString("tmall");
        array.AddString("taobao");

        plistDocument.WriteToFile(path);
    }
示例#24
0
        /// <summary>
        /// URLスキームを追加します
        /// </summary>
        /// <param name="path"> 出力先のパス </param>
        public static void AddIOSUrlScheme(string path)
        {
#if UNITY_IOS
            string        plistPath = Path.Combine(path, "Info.plist");
            PlistDocument plist     = new PlistDocument();

            // 読み込み
            plist.ReadFromFile(plistPath);

            PlistElementArray urlTypeArray   = plist.root.CreateArray("CFBundleURLTypes");
            PlistElementDict  urlTypeDict    = urlTypeArray.AddDict();
            PlistElementArray urlSchemeArray = urlTypeDict.CreateArray("CFBundleURLSchemes");

            SDKConfiguration sdkConfiguration = UrlSchemeEditTool.LoadSDKConfiguration();
            if (sdkConfiguration == null)
            {
                return;
            }

            var urlScheme = sdkConfiguration.IOSUrlScheme;
            var Validator = new UriSchemeValidator(urlScheme);
            if (!Validator.Validate())
            {
                Debug.LogError("iOSのURLスキーマが不正なのでURLスキーマの追加処理をスキップしました");
                return;
            }

            Uri uri;
            try
            {
                uri = new Uri(urlScheme);
            }
            catch (UriFormatException)
            {
                return;
            }

            // URLスキームを追加
            urlSchemeArray.AddString(uri.Scheme);

            // 書き込み
            plist.WriteToFile(plistPath);
#endif
        }
示例#25
0
    private static void DoAddSKAdNetworkItemsToInfo(string projectPath)
    {
        string infoPlistPath = Path.Combine(projectPath, "Info.plist");

        PlistDocument plistDoc = new PlistDocument();

        plistDoc.ReadFromFile(infoPlistPath);
        if (plistDoc.root != null)
        {
            PlistElementDict rootDict = plistDoc.root;

            PlistElement elementSKAdNetworkItems = rootDict["SKAdNetworkItems"];

            if (null == elementSKAdNetworkItems)
            {
                rootDict["SKAdNetworkItems"] = new PlistElementArray();

                elementSKAdNetworkItems = rootDict["SKAdNetworkItems"];
            }
            else
            {
                PlistElementArray arrayAdNetworkItems = elementSKAdNetworkItems.AsArray();
                int count = arrayAdNetworkItems.values.Count;
                arrayAdNetworkItems.values.RemoveRange(0, count);
            }

            PlistElementArray arrayItems = elementSKAdNetworkItems.AsArray();

            PlistElementArray addAdNetworks = DoGetAdNetworks();

            for (int i = 0; i < addAdNetworks.values.Count; i++)
            {
                PlistElementDict item = addAdNetworks.values[i] as PlistElementDict;
                arrayItems.values.Add(item);
            }

            plistDoc.WriteToFile(infoPlistPath);
        }
        else
        {
            Debug.LogError("Error: Can't open " + infoPlistPath);
        }
    }
示例#26
0
 private void AddDataToArray(object value, PlistElementArray elementArray)
 {
     if (value is int)
     {
         elementArray.AddInteger(Convert.ToInt32(value));
     }
     else if (value is bool)
     {
         elementArray.AddBoolean(Convert.ToBoolean(value));
     }
     else if (value is string)
     {
         elementArray.AddString(value.ToString());
     }
     else if (value is float)
     {
         elementArray.AddReal(Convert.ToSingle(value));
     }
 }
示例#27
0
    public static void PatchInfoPlist(string pathToBuiltProject)
    {
        string plistPath = Path.Combine(pathToBuiltProject, "Info.plist");

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistPath);


        // =================================
        // We must do this here instead of passing the plist to
        //  a useful helper function because Unity refuses to build functions
        //  where a variable of type PlistDocument is passed.

        string key = "UISupportedExternalAccessoryProtocols";

        string[] values = new string[3]
        {
            "io.structure.control",
            "io.structure.depth",
            "io.structure.infrared"
        };

        if (!plist.root.values.ContainsKey(key))
        {
            PlistElementArray array = new PlistElementArray();
            foreach (string value in values)
            {
                array.AddString(value);
            }

            plist.root.values.Add(new PlistEntry(key, array));
        }
        // =================================

        // Camera access on iOS10.
        plist.root.values.Add(new PlistEntry("NSCameraUsageDescription", new PlistElementString("Camera image used for motion tracking and AR compositing")));

        // Enable file sharing.
        plist.root.values.Add(new PlistEntry("UIFileSharingEnabled", new PlistElementBoolean(true)));

        plist.WriteToFile(plistPath);
    }
示例#28
0
        /// <summary>
        /// URLSchemes
        /// </summary>
        public static void SetURLSchemes(string buildPath, string urlIdentifier, List <string> schemeList)
        {
            PlistDocument plist = GetInfoPlist(buildPath);

            PlistElementArray urlTypes;

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

            PlistElementDict itmeDict = urlTypes.AddDict();

            itmeDict.SetString(XcodeProjectConst.URL_TYPE_ROLE_KEY, "Editor");
            itmeDict.SetString(XcodeProjectConst.URL_IDENTIFIER_KEY, urlIdentifier);

            PlistElementArray schemesArray = itmeDict.CreateArray(XcodeProjectConst.URL_SCHEMES_KEY);

            if (itmeDict.values.ContainsKey(XcodeProjectConst.URL_SCHEMES_KEY))
            {
                schemesArray = itmeDict[XcodeProjectConst.URL_SCHEMES_KEY].AsArray();
            }
            else
            {
                schemesArray = itmeDict.CreateArray(XcodeProjectConst.URL_SCHEMES_KEY);
            }

            for (int i = 0; i < schemesArray.values.Count; i++)
            {
                schemeList.Remove(schemesArray.values[i].AsString());
            }

            foreach (string scheme in schemeList)
            {
                schemesArray.AddString(scheme);
            }

            plist.WriteToFile(GetInfoPlistPath(buildPath));
        }
    public static void UpdateXCodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
                #if UNITY_IOS
        if (buildTarget == BuildTarget.iOS)
        {
            // Check Consumer Key
            if (string.IsNullOrEmpty(TwitterSettings.ConsumerKey))
            {
                TwitterKit.Internal.Utils.LogError(TwitterSettings.API_KEY_NOT_SET);
                return;
            }

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

            // Get root
            PlistElementDict rootDict = plist.root;

            // Modify Info.Plist for Twitter Kit (https://dev.twitter.com/twitterkit/ios/installation)
            PlistElementArray bundleURLTypesArray = rootDict[URL_TYPES] as PlistElementArray;
            if (bundleURLTypesArray == null)
            {
                bundleURLTypesArray = rootDict.CreateArray(URL_TYPES);
            }
            PlistElementDict  dict = bundleURLTypesArray.AddDict();
            PlistElementArray bundleURLSchemesArray = dict.CreateArray(URL_SCHEMES);
            bundleURLSchemesArray.AddString("twitterkit-" + TwitterSettings.ConsumerKey);
            PlistElementArray queriesSchemesArray = rootDict[APPLICATION_QUERIES_SCHEMES] as PlistElementArray;
            if (queriesSchemesArray == null)
            {
                queriesSchemesArray = rootDict.CreateArray(APPLICATION_QUERIES_SCHEMES);
            }
            queriesSchemesArray.AddString("twitter");
            queriesSchemesArray.AddString("twitterauth");

            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());
        }
                #endif
    }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target == BuildTarget.iOS)
        {
            // pbxプロジェクトファイルのパス
            string xcodeProjPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            // プロジェクトファイルの読み込み
            PBXProject proj     = new PBXProject();
            string     projFile = File.ReadAllText(xcodeProjPath);
            proj.ReadFromString(projFile);
            var targetName = PBXProject.GetUnityTargetName();
            var guid       = proj.TargetGuidByName(targetName);

            proj.AddFrameworkToProject(guid, "AuthenticationServices.framework", true);

            // SignInWithApple有効化
            var productName      = proj.GetBuildPropertyForAnyConfig(guid, "PRODUCT_NAME");
            var entitlementsPath = targetName + "/" + productName + ".entitlements";
            proj.SetBuildProperty(guid, "CODE_SIGN_ENTITLEMENTS", entitlementsPath);

            var entPath = path + "/" + entitlementsPath;
            {
                var plist = new PlistDocument();
                if (File.Exists(entPath))
                {
                    plist.ReadFromFile(entPath);
                }

                var rootDict = plist.root;

                var valueArray = new PlistElementArray();
                valueArray.AddString("Default");
                rootDict.values["com.apple.developer.applesignin"] = valueArray;

                File.WriteAllText(entPath, plist.WriteToString());
            }

            // 設定したデータを書き出す
            proj.WriteToFile(xcodeProjPath);
        }
    }