public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { if (target == BuildTarget.iOS) { string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetBoolean("AppsFlyerShouldSwizzle", appsFlyerShouldSwizzle); rootDict.SetBoolean("isDebug", isDebug); rootDict.SetString("devKey", devKey); rootDict.SetString("appID", appID); File.WriteAllText(plistPath, plist.WriteToString()); Debug.Log("Info.plist updated with AppsFlyerShouldSwizzle"); } else if (target == BuildTarget.Android) { if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string path = dirPath + "/" + propFileName; string text = "AF_DEV_KEY=" + devKey + "\nAF_DEBUG=" + isDebug; StreamWriter writer = new StreamWriter(path, true); writer.WriteLine(text); writer.Close(); } }
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { // Get pbx string projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); string target = pbxProject.TargetGuidByName("Unity-iPhone"); // set enable bitcode off pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); pbxProject.WriteToFile(projectPath); // Get plist string plistPath = pathToBuiltProject + "/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 = "CFBundleVersion"; rootDict.SetString(buildKey, "2.3.4"); rootDict.SetString("NSCameraUsageDescription", "Use to assess AR"); rootDict.SetString("NSPhotoLibraryUsageDescription", "Use to save screenshot"); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
//设置info.plist文件 void SetInfo(string pathToBuildProject) { string plistPath = pathToBuildProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict plistRoot = plist.root; //指定打包时使用的ProvisioningProfile PlistElementDict dict = plistRoot.CreateDict("provisioningProfiles"); dict.SetString(PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS), PlayerSettings.iOS.iOSManualProvisioningProfileID); plistRoot.SetString("method", PlayerSettings.iOS.iOSManualProvisioningProfileType == ProvisioningProfileType.Development ? "development" : "app-store"); plistRoot.SetString("NSCameraUsageDescription", "需要使用相机"); plistRoot.SetString("NSCalendarsUsageDescription", "需要使用日历"); plistRoot.SetString("NSPhotoLibraryUsageDescription", "需要使用相册"); plistRoot.SetString("NSLocationWhenInUseUsageDescription", "需要访问地理位置"); //龙图SDK设置URL Schemes PlistElementArray URLArray = plistRoot.CreateArray("CFBundleURLTypes"); PlistElementDict elementDict = URLArray.AddDict();; elementDict.SetString("CFBundleURLName", "GoogleID"); elementDict.CreateArray("CFBundleURLSchemes").AddString("com.googleusercontent.apps.837194912770-vt71nif9hiifrdb2hcg2l2ejc94rnloq"); File.WriteAllText(plistPath, plist.WriteToString()); }
public static void LinkLibraries(string path) { // linked library string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); string target = GetTargetGuid(proj); // disable bit-code proj.SetBuildProperty(target, "ENABLE_BITCODE", "false"); // Frameworks foreach (string framework in ProjectFrameworks) { proj.AddFrameworkToProject(target, framework, true); } File.WriteAllText(projPath, proj.WriteToString()); // permission string pListPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(pListPath)); PlistElementDict rootDic = plist.root; var cameraPermission = "NSCameraUsageDescription"; var micPermission = "NSMicrophoneUsageDescription"; rootDic.SetString(cameraPermission, "Video need to use camera"); rootDic.SetString(micPermission, "Voice call need to user mic"); File.WriteAllText(pListPath, plist.WriteToString()); }
public static void EditXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { string WEBENGAGE_LICENSE_CODE = "YOUR-WEBENGAGE-LICENSE-CODE"; string logLevel = "VERBOSE"; bool apnsAutoRegister = true; bool trackLocation = false; // Update plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("WEGLicenseCode", WEBENGAGE_LICENSE_CODE); rootDict.SetString("WEGLogLevel", logLevel); rootDict.SetBoolean("WEGApnsAutoRegister", apnsAutoRegister); if (trackLocation) { PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes"); bgModes.AddString("location"); // TODO: Background location useage key (new in iOS 8) //rootDict.SetString("NSLocationAlwaysUsageDescription", "Uses background location"); } // Write to Info.plist file File.WriteAllText(plistPath, plist.WriteToString()); } }
static void EditorPlist(string path) { string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("NSPhotoLibraryUsageDescription", "保存截图到相册,需要访问你的相册"); rootDict.SetString("NSContactsUsageDescription", "使用通讯录"); rootDict.SetString("NSMicrophoneUsageDescription", "使用麦克风"); rootDict.SetString("NSCameraUsageDescription", "使用相机"); rootDict.SetString("NSLocationWhenInUseUsageDescription", "地理位置"); rootDict.SetBoolean("UIFileSharingEnabled", DebugUtils.DebugMode); switch (channelName) { case "": { break; } } File.WriteAllText(plistPath, plist.WriteToString()); }
private static void AddUrlType(PlistElementDict dict, string role, string name, string scheme) { //添加URLTypes PlistElementArray URLTypes; if (dict.values.ContainsKey("CFBundleURLTypes")) { URLTypes = dict["CFBundleURLTypes"].AsArray(); } else { URLTypes = dict.CreateArray("CFBundleURLTypes"); } PlistElementDict elementDict = new PlistElementDict(); elementDict.SetString("CFBundleTypeRole", role); elementDict.SetString("CFBundleURLName", name); elementDict.CreateArray("CFBundleURLSchemes").AddString(scheme); URLTypes.values.Add(elementDict); //添加LSApplicationQueriesSchemes PlistElementArray schemes; if (dict.values.ContainsKey("LSApplicationQueriesSchemes")) { schemes = dict["LSApplicationQueriesSchemes"].AsArray(); } else { schemes = dict.CreateArray("LSApplicationQueriesSchemes"); } schemes.AddString(name); }
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()); } }