Unity iOS 建構後自動配置 Xcode 專案的編輯器工具。透過 JSON 配置檔案宣告式管理 Info.plist、框架、函式庫、建構屬性、Capabilities、CocoaPods 來源、本地化等所有 Xcode 設定,無需手動操作 Xcode。
.framework / .tbdENABLE_BITCODE、GCC_ENABLE_OBJC_EXCEPTIONS).lproj/InfoPlist.strings,支援應用名稱多語言.framework/.bundleOTHER_LDFLAGS 等XCodeConfig.json 深度遞迴合併,適合多模組協作任選以下方式之一:
方式一:修改 manifest.json
在 Packages/manifest.json 的 dependencies 中新增:
"com.gameframex.unity.xcode": "https://github.com/gameframex/com.gameframex.unity.xcode.git"
方式二:Package Manager Git URL
Unity 編輯器 → Window → Package Manager → Add package from git URL,輸入:
https://github.com/gameframex/com.gameframex.unity.xcode.git
方式三:手動下載
克隆或下載本倉庫,放入 Unity 專案的 Packages 目錄即可自動識別。
Editor/XCodeConfigDemo.json 複製到專案任意目錄XCodeConfig.json配置檔案必須命名為 XCodeConfig.json,支援放在專案任意位置,支援多個檔案並存(會自動合併)。
{
"swiftBridging": true,
"signing": {},
"plist": {},
"environmentVariables": {},
"launcherArgs": [],
"podSource": [],
"localizations": [],
"capabilities": {},
"unityFramework": {},
"unityMain": {}
}
| 欄位 | 型別 | 說明 |
|---|---|---|
swiftBridging | bool | 啟用 Swift 橋接標頭檔案自動產生(預設:true) |
signing | object | 程式碼簽名配置(詳見下方) |
plist | object | Info.plist 鍵值對,值支援任意型別 |
environmentVariables | object | XcScheme 環境變數,鍵值均為字串 |
launcherArgs | string[] | XcScheme 啟動參數列表 |
podSource | string[] | CocoaPods 來源位址列表,替換 Podfile 預設來源 |
localizations | array | 本地化配置(詳見下方) |
capabilities | object | iOS 應用能力配置(詳見下方) |
unityFramework | object | UnityFramework target 配置 |
unityMain | object | Unity-iPhone target 配置 |
兩者結構相同,分別對應 Xcode 專案中的 UnityFramework 和 Unity-iPhone target:
{
"libs": { "+": [], "-": [] },
"frameworks": { "+": [], "-": [] },
"properties": { "=": {}, "+": {}, "-": {} },
"files": {},
"folders": {},
"filesCompileFlag": {},
"otherLinkerFlag": {},
"runPathSearchPaths": {},
"pods": {}
}
{
"libs": {
"+": ["libz.tbd", "libicucore.tbd"],
"-": ["libstdc++.tbd"]
}
}
+ 要新增的函式庫名稱列表- 要移除的函式庫名稱列表{
"frameworks": {
"+": ["WebKit.framework", "UserNotifications.framework"],
"-": []
}
}
+ 要新增的框架名稱列表- 要移除的框架名稱列表{
"properties": {
"=": { "ENABLE_BITCODE": "NO" },
"+": { "OTHER_CFLAGS": ["-flag1", "-flag2"] },
"-": { "UNUSED_FLAG": [""] }
}
}
= 設定屬性(鍵值對,覆蓋已有值)+ 追加屬性(值為陣列時追加到現有列表)- 移除屬性{
"files": {
"ios_libs.txt": "Classes/ios_libs.txt"
}
}
Assets 同級){
"folders": {
"XC": "Classes/XC"
}
}
.framework 和 .bundle{
"filesCompileFlag": {
"Classes/PluginBase/UnityViewControllerListener.mm": "-fobjc-arc"
}
}
{
"otherLinkerFlag": {
"OTHER_LDFLAGS": ["-ObjC"]
}
}
{
"runPathSearchPaths": {
"LD_RUNPATH_SEARCH_PATHS": ["@executable_path/Frameworks"]
}
}
僅在 Unity-iPhone(主)target 上生效,所有欄位均可選。
{
"signing": {
"teamId": "XXXXXXXXXX",
"bundleId": "com.company.app",
"codeSignIdentity": "Apple Development",
"codeSignStyle": "Automatic",
"provisioningProfileSpecifier": ""
}
}
| 欄位 | 型別 | 說明 |
|---|---|---|
teamId | string | Apple 開發者團隊 ID(DEVELOPMENT_TEAM) |
bundleId | string | 應用包名(PRODUCT_BUNDLE_IDENTIFIER) |
codeSignIdentity | string | 簽名身份,可選值:Apple Development、Apple Distribution、iPhone Developer、iPhone Distribution |
codeSignStyle | string | 簽名方式:Automatic(自動)或 Manual(手動) |
provisioningProfileSpecifier | string | 描述檔名稱(僅 Manual 模式需要) |
僅在 Unity-iPhone(主)target 上生效。啟用後(預設啟用)自動建立 Swift 檔案和橋接標頭檔案,實現 Objective-C/Swift 混編。無 Xcode 彈窗提示,適合 CI 自動化建構。
{
"swiftBridging": true
}
true,設為 false 可關閉gameframex_swift_bridging.swift 和 Unity-iPhone-Bridging-Header.hSWIFT_VERSION 為 5.0 並配置 SWIFT_OBJC_BRIDGING_HEADER{
"capabilities": {
"inAppPurchase": true,
"gameCenter": false,
"pushNotifications": false,
"signInWithApple": false,
"backgroundModes": ["audio", "remote-notification"],
"iCloud": {
"keyValueStorage": false,
"iCloudDocument": false,
"customContainers": []
},
"appGroups": [],
"associatedDomains": [],
"keychainSharing": false,
"healthKit": false,
"siri": false,
"personalVPN": false,
"dataProtection": false
}
}
| 欄位 | 型別 | 說明 |
|---|---|---|
inAppPurchase | bool | 內購 |
gameCenter | bool | Game Center |
pushNotifications | bool | 推播通知 |
signInWithApple | bool | Sign In with Apple |
backgroundModes | string[] | 背景模式,可選值:audio、location、voip、newsstand、external、bluetooth、bluetooth-peripheral、fetch、remote-notification |
iCloud.keyValueStorage | bool | iCloud 鍵值儲存 |
iCloud.iCloudDocument | bool | iCloud 文件儲存 |
iCloud.customContainers | string[] | iCloud 自訂容器 |
appGroups | string[] | App Groups 識別符 |
associatedDomains | string[] | 關聯網域(Universal Links) |
keychainSharing | bool 或 object | Keychain Sharing。false 停用,true 使用預設分組,或 {"accessGroups": ["group1"]} 指定自訂分組 |
healthKit | bool | HealthKit 健康資料存取 |
siri | bool | Siri 語音助理整合 |
personalVPN | bool | Personal VPN 個人 VPN |
dataProtection | bool | Data Protection 檔案層級加密 |
{
"localizations": [
{
"languageCode": "en",
"validMap": [
{ "key": "CFBundleDisplayName", "value": "My Game" }
]
},
{
"languageCode": "zh-Hans",
"validMap": [
{ "key": "CFBundleDisplayName", "value": "我的游戏" }
]
}
]
}
languageCode — ISO 639-1 語言代碼(中文使用 zh-Hans 簡體 / zh-Hant 繁體)validMap — 鍵值對列表,每個項包含 key 和 value.lproj/InfoPlist.strings 檔案並新增到工程支援任意層級巢狀,常見配置:
{
"plist": {
"CFBundleURLTypes": [
{
"CFBundleTypeRole": "Editor",
"CFBundleURLSchemes": ["myapp"],
"CFBundleURLName": "com.example.myapp"
}
],
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true
},
"NSCameraUsageDescription": "需要相機權限用於掃碼",
"ITSAppUsesNonExemptEncryption": false
}
}
pods 配置在 unityMain 和/或 unityFramework 內部。每個 target 的 pods 會注入到對應的 Podfile target 區塊(target 'Unity-iPhone' do 或 target 'UnityFramework' do)中。自動跳過已存在的同名 pod。
{
"unityFramework": {
"pods": {
"FirebaseAnalytics": "",
"FBSDKLoginKit": "~> 14.0"
}
},
"unityMain": {
"pods": {
"SomePod": "~> 1.0"
}
}
}
pod 'Name',值非空 → pod 'Name', 'Value'pod install,需手動或在 CI 中執行專案中可以放置多個 XCodeConfig.json 檔案(如不同模組各自維護一份),建構時會自動發現並深度合併:
這使得多 SDK / 多模組的 Xcode 配置可以獨立管理、互不干擾。
{
"swiftBridging": true,
"signing": {
"teamId": "XXXXXXXXXX",
"bundleId": "com.company.app",
"codeSignIdentity": "Apple Development",
"codeSignStyle": "Automatic",
"provisioningProfileSpecifier": ""
},
"plist": {
"CFBundleURLTypes": [
{
"CFBundleTypeRole": "Editor",
"CFBundleURLSchemes": ["bbqgame"],
"CFBundleURLName": "com.smartdogx.bbq"
},
{
"CFBundleTypeRole": "Editor",
"CFBundleURLSchemes": ["wx5dfe430e96b395a6"]
}
],
"LSApplicationQueriesSchemes": [
"weixin", "wechat", "mqqapi"
],
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true,
"NSExceptionDomains": {
"qq.com": {
"NSIncludesSubdomains": true,
"NSThirdPartyExceptionAllowsInsecureHTTPLoads": true,
"NSThirdPartyExceptionRequiresForwardSecrecy": false
}
}
},
"NSCameraUsageDescription": "需要您的相機權限",
"NSMicrophoneUsageDescription": "需要您的麥克風權限",
"NSPhotoLibraryUsageDescription": "需要您的相簿權限",
"ITSAppUsesNonExemptEncryption": false,
"NSUserTrackingUsageDescription": "此識別符將用於向您推薦個人化廣告"
},
"environmentVariables": {
"IDEPreferLogStreaming": "YES",
"OS_ACTIVITY_MODE": "disable"
},
"launcherArgs": ["-debug"],
"localizations": [
{
"languageCode": "en",
"validMap": [
{ "key": "CFBundleDisplayName", "value": "My Game" }
]
},
{
"languageCode": "zh-Hans",
"validMap": [
{ "key": "CFBundleDisplayName", "value": "我的游戏" }
]
}
],
"podSource": [
"https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git"
],
"capabilities": {
"inAppPurchase": true,
"gameCenter": false,
"pushNotifications": false,
"signInWithApple": false,
"backgroundModes": [],
"iCloud": {
"keyValueStorage": false,
"iCloudDocument": false,
"customContainers": []
},
"appGroups": [],
"associatedDomains": [],
"keychainSharing": false,
"healthKit": false,
"siri": false,
"personalVPN": false,
"dataProtection": false
},
"unityFramework": {
"libs": {
"+": ["libicucore.tbd", "libz.tbd"],
"-": []
},
"frameworks": {
"+": ["WebKit.framework", "Security.framework"],
"-": []
},
"properties": {
"=": {
"ENABLE_BITCODE": "NO",
"GCC_ENABLE_OBJC_EXCEPTIONS": true,
"CLANG_ENABLE_OBJC_ARC": true
},
"+": {},
"-": {}
},
"filesCompileFlag": {},
"otherLinkerFlag": {
"OTHER_LDFLAGS": ["-ObjC"]
},
"pods": {
"FirebaseAnalytics": ""
},
"files": {},
"folders": {}
},
"unityMain": {
"libs": {
"+": ["libz.tbd"],
"-": []
},
"frameworks": {
"+": ["WebKit.framework"],
"-": []
},
"properties": {
"="": { "ENABLE_BITCODE": "NO" },
"+": {},
"-": {}
},
"otherLinkerFlag": {
"OTHER_LDFLAGS": ["-ObjC"]
},
"files": {},
"folders": {}
}
}
XCodeConfig.json,否則不會被識別#if UNITY_IOS 條件編譯下,不會影響其他平台[PostProcessBuild(ushort.MaxValue)] 優先級執行,即所有其他後處理完成後執行