1+ #if UNITY_IOS
2+ using System ;
3+ using System . Collections ;
4+ using UnityEditor . iOS . Xcode ;
5+ using UnityEngine ;
6+
7+ namespace GameFrameX . Xcode . Editor
8+ {
9+ internal partial class PostProcessBuildHelper
10+ {
11+ /// <summary>
12+ /// 设置Capabilities
13+ /// </summary>
14+ /// <param name="pbxProject">PBX项目</param>
15+ /// <param name="targetGuid">目标GUID</param>
16+ /// <param name="path"></param>
17+ /// <param name="hashtable">配置数据</param>
18+ static void SetCapabilities ( PBXProject pbxProject , string targetGuid , string path , Hashtable hashtable )
19+ {
20+ try
21+ {
22+ if ( hashtable == null )
23+ {
24+ return ;
25+ }
26+
27+ Debug . Log ( "开始设置Capabilities" ) ;
28+
29+ var projectCapabilityManager = new ProjectCapabilityManager ( path + "/Unity-iPhone.xcodeproj/project.pbxproj" , "gameframex.entitlements" , "Unity-iPhone" ) ;
30+
31+ // In-App Purchase
32+ if ( hashtable . ContainsKey ( "inAppPurchase" ) && ( bool ) hashtable [ "inAppPurchase" ] )
33+ {
34+ projectCapabilityManager . AddInAppPurchase ( ) ;
35+ Debug . Log ( "已添加 In-App Purchase Capability" ) ;
36+ }
37+
38+ // Game Center
39+ if ( hashtable . ContainsKey ( "gameCenter" ) && ( bool ) hashtable [ "gameCenter" ] )
40+ {
41+ projectCapabilityManager . AddGameCenter ( ) ;
42+ Debug . Log ( "已添加 Game Center Capability" ) ;
43+ }
44+
45+ // Push Notifications
46+ if ( hashtable . ContainsKey ( "pushNotifications" ) && ( bool ) hashtable [ "pushNotifications" ] )
47+ {
48+ projectCapabilityManager . AddPushNotifications ( false ) ;
49+ Debug . Log ( "已添加 Push Notifications Capability" ) ;
50+ }
51+
52+ // Sign In with Apple
53+ if ( hashtable . ContainsKey ( "signInWithApple" ) && ( bool ) hashtable [ "signInWithApple" ] )
54+ {
55+ projectCapabilityManager . AddSignInWithApple ( ) ;
56+ Debug . Log ( "已添加 Sign In with Apple Capability" ) ;
57+ }
58+
59+ // Background Modes
60+ if ( hashtable . ContainsKey ( "backgroundModes" ) )
61+ {
62+ var backgroundModes = hashtable [ "backgroundModes" ] as ArrayList ;
63+ if ( backgroundModes != null && backgroundModes . Count > 0 )
64+ {
65+ var modes = new BackgroundModesOptions ( ) ;
66+ foreach ( string mode in backgroundModes )
67+ {
68+ switch ( mode . ToLower ( ) )
69+ {
70+ case "audio" :
71+ modes |= BackgroundModesOptions . AudioAirplayPiP ;
72+ break ;
73+ case "location" :
74+ modes |= BackgroundModesOptions . LocationUpdates ;
75+ break ;
76+ case "voip" :
77+ modes |= BackgroundModesOptions . VoiceOverIP ;
78+ break ;
79+ case "newsstand" :
80+ modes |= BackgroundModesOptions . NewsstandDownloads ;
81+ break ;
82+ case "external" :
83+ modes |= BackgroundModesOptions . ExternalAccessoryCommunication ;
84+ break ;
85+ case "bluetooth" :
86+ modes |= BackgroundModesOptions . UsesBluetoothLEAccessory ;
87+ break ;
88+ case "bluetooth-peripheral" :
89+ modes |= BackgroundModesOptions . ActsAsABluetoothLEAccessory ;
90+ break ;
91+ case "fetch" :
92+ modes |= BackgroundModesOptions . BackgroundFetch ;
93+ break ;
94+ case "remote-notification" :
95+ modes |= BackgroundModesOptions . RemoteNotifications ;
96+ break ;
97+ }
98+ }
99+
100+ projectCapabilityManager . AddBackgroundModes ( modes ) ;
101+ Debug . Log ( $ "已添加 Background Modes Capability: { string . Join ( ", " , backgroundModes . ToArray ( ) ) } ") ;
102+ }
103+ }
104+
105+ // iCloud
106+ if ( hashtable . ContainsKey ( "iCloud" ) )
107+ {
108+ var iCloudConfig = hashtable [ "iCloud" ] as Hashtable ;
109+ if ( iCloudConfig != null )
110+ {
111+ bool enableKeyValueStorage = iCloudConfig . ContainsKey ( "keyValueStorage" ) && ( bool ) iCloudConfig [ "keyValueStorage" ] ;
112+ bool enableiCloudDocument = iCloudConfig . ContainsKey ( "iCloudDocument" ) && ( bool ) iCloudConfig [ "iCloudDocument" ] ;
113+
114+ var customContainers = iCloudConfig [ "customContainers" ] as ArrayList ;
115+ string [ ] containers = null ;
116+ if ( customContainers != null && customContainers . Count > 0 )
117+ {
118+ containers = new string [ customContainers . Count ] ;
119+ for ( int i = 0 ; i < customContainers . Count ; i ++ )
120+ {
121+ containers [ i ] = customContainers [ i ] . ToString ( ) ;
122+ }
123+ }
124+
125+ projectCapabilityManager . AddiCloud ( enableKeyValueStorage , enableiCloudDocument , containers ) ;
126+ Debug . Log ( "已添加 iCloud Capability" ) ;
127+ }
128+ }
129+
130+ // App Groups
131+ if ( hashtable . ContainsKey ( "appGroups" ) )
132+ {
133+ var appGroups = hashtable [ "appGroups" ] as ArrayList ;
134+ if ( appGroups != null && appGroups . Count > 0 )
135+ {
136+ string [ ] groups = new string [ appGroups . Count ] ;
137+ for ( int i = 0 ; i < appGroups . Count ; i ++ )
138+ {
139+ groups [ i ] = appGroups [ i ] . ToString ( ) ;
140+ }
141+
142+ projectCapabilityManager . AddAppGroups ( groups ) ;
143+ Debug . Log ( $ "已添加 App Groups Capability: { string . Join ( ", " , groups ) } ") ;
144+ }
145+ }
146+
147+ // Associated Domains
148+ if ( hashtable . ContainsKey ( "associatedDomains" ) )
149+ {
150+ var domains = hashtable [ "associatedDomains" ] as ArrayList ;
151+ if ( domains != null && domains . Count > 0 )
152+ {
153+ string [ ] domainArray = new string [ domains . Count ] ;
154+ for ( int i = 0 ; i < domains . Count ; i ++ )
155+ {
156+ domainArray [ i ] = domains [ i ] . ToString ( ) ;
157+ }
158+
159+ projectCapabilityManager . AddAssociatedDomains ( domainArray ) ;
160+ Debug . Log ( $ "已添加 Associated Domains Capability: { string . Join ( ", " , domainArray ) } ") ;
161+ }
162+ }
163+
164+ projectCapabilityManager . WriteToFile ( ) ;
165+ }
166+ catch ( Exception e )
167+ {
168+ Debug . LogError ( e ) ;
169+ }
170+ }
171+ }
172+ }
173+ #endif
0 commit comments