@@ -72,15 +72,13 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
72
72
tempProject . ReadFromString ( File . ReadAllText ( projectPath ) ) ;
73
73
string targetId = GetMainTargetGUID ( tempProject ) ;
74
74
75
- // This will look for an entitlements file in the unity project, and add it to the
76
- // PBX Project if found.
77
- AddEntitlements ( tempProject , path , targetId ) ;
75
+ var capabilityManager = new ProjectCapabilityManager ( projectPath , "dev.entitlements" , null , targetId ) ;
78
76
79
77
if ( path . Contains ( "FirebaseMessaging" ) ) {
80
- MakeChangesForMessaging ( tempProject , path , targetId ) ;
78
+ MakeChangesForMessaging ( capabilityManager ) ;
81
79
}
82
80
if ( path . Contains ( "FirebaseAuth" ) ) {
83
- MakeChangesForAuth ( tempProject , path , targetId ) ;
81
+ MakeChangesForAuth ( capabilityManager ) ;
84
82
}
85
83
// Bitcode is being deprecated by xcode, but Unity defaults to it on, so turn it off.
86
84
tempProject . SetBuildProperty ( targetId , "ENABLE_BITCODE" , "NO" ) ;
@@ -89,67 +87,19 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
89
87
File . WriteAllText ( projectPath , tempProject . WriteToString ( ) ) ;
90
88
}
91
89
92
- static void AddEntitlements ( object projectObj , string path , string targetId ) {
93
- var project = ( PBXProject ) projectObj ;
94
- string [ ] entitlements = AssetDatabase . FindAssets ( "dev" )
95
- . Select ( AssetDatabase . GUIDToAssetPath )
96
- . Where ( p => p . Contains ( "dev.entitlements" ) )
97
- . ToArray ( ) ;
98
- // Only some APIs require entitlements so length 0 is okay
99
- if ( entitlements . Length == 0 ) {
100
- Debug . Log ( "No entitlement file found." ) ;
101
- return ;
102
- }
103
- if ( entitlements . Length > 1 ) {
104
- throw new System . InvalidOperationException ( "Multiple entitlements found." ) ;
105
- }
106
- Debug . Log ( "Entitlement file found." ) ;
107
- string entitlementPath = entitlements [ 0 ] ;
108
-
109
- string entitlementFileName = Path . GetFileName ( entitlementPath ) ;
110
- string relativeDestination = Google . IOSResolver . PROJECT_NAME + "/" + entitlementFileName ;
111
- FileUtil . CopyFileOrDirectory ( entitlementPath , path + "/" + relativeDestination ) ;
112
- project . AddFile ( relativeDestination , entitlementFileName ) ;
113
- // Not enough to add the entitlement: need to force the project to recognize it.
114
- project . AddBuildProperty ( targetId , "CODE_SIGN_ENTITLEMENTS" , relativeDestination ) ;
115
- Debug . Log ( "Added entitlement to xcode project." ) ;
116
- }
117
-
118
- static void MakeChangesForMessaging ( object projectObj , string path , string targetId ) {
119
- var project = ( PBXProject ) projectObj ;
90
+ static void MakeChangesForMessaging ( ProjectCapabilityManager capabilityManager ) {
120
91
Debug . Log ( "Messaging testapp detected." ) ;
121
- AddFramework ( project , targetId , "UserNotifications.framework" ) ;
122
- EnableRemoteNotification ( project , path , targetId ) ;
92
+ capabilityManager . AddPushNotifications ( true ) ;
93
+ capabilityManager . AddBackgroundModes ( BackgroundModesOptions . RemoteNotifications ) ;
123
94
Debug . Log ( "Finished making messaging-specific changes." ) ;
124
95
}
125
96
126
- static void MakeChangesForAuth ( object projectObj , string path , string targetId ) {
127
- var project = ( PBXProject ) projectObj ;
97
+ static void MakeChangesForAuth ( ProjectCapabilityManager capabilityManager ) {
128
98
Debug . Log ( "Auth testapp detected." ) ;
129
- AddFramework ( project , targetId , "UserNotifications.framework" ) ;
99
+ capabilityManager . AddPushNotifications ( true ) ;
130
100
Debug . Log ( "Finished making auth-specific changes." ) ;
131
101
}
132
102
133
- static void EnableRemoteNotification ( object projectObj , string path , string targetId ) {
134
- var project = ( PBXProject ) projectObj ;
135
- Debug . Log ( "Adding remote-notification to UIBackgroundModes" ) ;
136
- var plist = new PlistDocument ( ) ;
137
- string plistPath = path + "/Info.plist" ;
138
- plist . ReadFromString ( File . ReadAllText ( plistPath ) ) ;
139
- PlistElementDict rootDict = plist . root ;
140
- PlistElementArray backgroundModes = rootDict . CreateArray ( "UIBackgroundModes" ) ;
141
- backgroundModes . AddString ( "remote-notification" ) ;
142
- File . WriteAllText ( plistPath , plist . WriteToString ( ) ) ;
143
- Debug . Log ( "Finished adding remote-notification." ) ;
144
- }
145
-
146
- static void AddFramework ( object projectObj , string targetId , string framework ) {
147
- var project = ( PBXProject ) projectObj ;
148
- Debug . LogFormat ( "Adding framework to xcode project: {0}." , framework ) ;
149
- project . AddFrameworkToProject ( targetId , framework , false ) ;
150
- Debug . Log ( "Finished adding framework." ) ;
151
- }
152
-
153
103
static string GetMainTargetGUID ( object pbxProjectObj ) {
154
104
var pbxProject = ( PBXProject ) pbxProjectObj ;
155
105
// In 2019.3 Unity changed this API without an automated update path via the api-updater.
0 commit comments