ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Unity打包xcode修改工程配置代码

2022-06-08 15:35:27  阅读:251  来源: 互联网

标签:pbxProject xcode targetGuid Sample Unity var using plist 打包


 1 using System.IO;
 2 using UnityEngine;
 3 using UnityEditor;
 4 using UnityEditor.iOS.Xcode;
 5 using UnityEditor.Callbacks;
 6 using System.Collections;
 7 
 8 public class XcodeSettingsPostProcesser
 9 {
10 
11     [PostProcessBuildAttribute (0)]
12     public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBuiltProject)
13     {
14 
15         // Stop processing if targe is NOT iOS
16         if (buildTarget != BuildTarget.iOS)
17             return; 
18 
19         // Initialize PbxProject
20         var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
21         PBXProject pbxProject = new PBXProject ();
22         pbxProject.ReadFromFile (projectPath);
23         string targetGuid = pbxProject.TargetGuidByName ("Unity-iPhone");
24 
25         // Sample of adding build property
26         pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-all_load");
27 
28         // Sample of setting build property
29         pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
30 
31         // Sample of update build property
32         pbxProject.UpdateBuildProperty(targetGuid, "OTHER_LDFLAGS", new string[]{"-ObjC"}, new string[]{"-weak_framework"});
33 
34         // Sample of adding REQUIRED framwrok
35         pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);
36 
37         // Sample of adding OPTIONAL framework
38         pbxProject.AddFrameworkToProject(targetGuid, "SafariServices.framework", true);
39 
40         // Sample of setting compile flags
41         var guid = pbxProject.FindFileGuidByProjectPath("Classes/UI/Keyboard.mm");
42         var flags = pbxProject.GetCompileFlagsForFile(targetGuid, guid);
43         flags.Add("-fno-objc-arc");
44         pbxProject.SetCompileFlagsForFile(targetGuid, guid, flags);
45 
46         // Apply settings
47         File.WriteAllText (projectPath, pbxProject.WriteToString ());
48 
49         // Samlpe of editing Info.plist
50         var plistPath = Path.Combine (pathToBuiltProject, "Info.plist");
51         var plist = new PlistDocument ();
52         plist.ReadFromFile (plistPath);
53 
54         // Add string setting
55         plist.root.SetString ("hogehogeId", "dummyid");
56 
57         // Add URL Scheme
58         var array = plist.root.CreateArray ("CFBundleURLTypes");
59         var urlDict = array.AddDict ();
60         urlDict.SetString ("CFBundleURLName", "hogehogeName");
61         var urlInnerArray = urlDict.CreateArray ("CFBundleURLSchemes");
62         urlInnerArray.AddString ("hogehogeValue");
63 
64         // Apply editing settings to Info.plist
65         plist.WriteToFile (plistPath);
66     }
67 }

 

标签:pbxProject,xcode,targetGuid,Sample,Unity,var,using,plist,打包
来源: https://www.cnblogs.com/hecanlin/p/16355837.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有