Unity 打包到XCode自动化设置参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
{
    if (buildTarget != BuildTarget.iOS)
        return;
 
    string pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
    var pbxProject = new PBXProject();
    pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));
    string targetGuid = pbxProject.GetUnityMainTargetGuid();
    string frameworkGuid = pbxProject.GetUnityFrameworkTargetGuid();
 
 
    // 设置关闭Bitcode
    pbxProject.SetBuildProperty(targetGuid, ENABLE_BITCODE_KEY, "NO");
    pbxProject.SetBuildProperty(frameworkGuid, ENABLE_BITCODE_KEY, "NO");
 
    // xcode archive filed
    var token = pbxProject.GetBuildPropertyForAnyConfig(targetGuid, "USYM_UPLOAD_AUTH_TOKEN");
    if (string.IsNullOrEmpty(token))
    {
        token = "FakeToken";
    }
    pbxProject.SetBuildProperty(targetGuid, USYM_UPLOAD_AUTH_TOKEN, token);
    pbxProject.SetBuildProperty(frameworkGuid, USYM_UPLOAD_AUTH_TOKEN, token);
 
    //添加系统库(Unity默认会添加部分库,不能添加重复的库,否则会有问题)
    //例
    pbxProject.AddFrameworkToProject(frameworkGuid, "CoreTelephony.framework", false);
 
 
    //添加tbd
    //例
    string fileGuidSqlite = pbxProject.AddFile("usr/lib/libsqlite3.tbd", "Libraries/libsqlite3.tbd", PBXSourceTree.Sdk);
 
    //添加引用的资源 如 .bundle文件
    //例
    string p = .bundle地址;
 
    string bun = pbxProject.AddFile(p, "名称.bundle", PBXSourceTree.Absolute);
    pbxProject.AddFileToBuild(targetGuid,  bun);
 
    //修改Info.plist文件
    SetInfoPlist(buildPath);
 
    File.WriteAllText(pbxProjPath, pbxProject.WriteToString());
 
    UnityEngine.Debug.Log("PBXProject : ---->" + pbxProject.WriteToString());
}
 
public static void SetInfoPlist(string buildPath)
{
    List<string> privacySensiticeData = new List<string>();
 
    PlistDocument plist = GetInfoPlist(buildPath);
 
    //选择语言(字符串)
    plist.root.SetString("NSPhotoLibraryAddUsageDescription", "此App需要您的同意,才能保存图片到您的相册");
    plist.root.SetString("NSPhotoLibraryUsageDescription", "此App需要您的同意才能读取媒体资料库");
    //(bool值)
    plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false);
 
    //设置LSApplicationQueriesSchemes(数组)
    //例
    PlistElementArray loginChannelsArr;
    loginChannelsArr = plist.root.CreateArray("LSApplicationQueriesSchemes");
    loginChannelsArr.AddString("mqqapi");
    loginChannelsArr.AddString("mqq");
 
    //配置(字典)
    PlistElementDict plistDic;
    plistDic = plist.root.CreateDict("NSAppTransportSecurity");
    plistDic.SetBoolean("NSAllowsArbitraryLoads", true);
 
    // 添加 url scheme
    PlistElementArray urlTypes = plist.root.CreateArray("CFBundleURLTypes");
    PlistElementDict wxUrl = urlTypes.AddDict();
    wxUrl.SetString("CFBundleTypeRole", "Editor");
    wxUrl.SetString("CFBundleURLName", "weixin");
    wxUrl.SetString("CFBundleURLSchemes", "wx...............");
    PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes");
    wxUrlScheme.AddString( "wx...............");
 
    plist.WriteToFile(GetInfoPlistPath(buildPath));
}

 

posted @   kawerd  阅读(943)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示