@@ -64,20 +64,23 @@ internal class XcodeProjectPatcher : AssetPostprocessor {
6464 private static bool Enabled {
6565 get {
6666 return ( EditorUserBuildSettings . activeBuildTarget ==
67- BuildTarget . iOS ) && Google . IOSResolver . Enabled ;
67+ BuildTarget . iOS ||
68+ EditorUserBuildSettings . activeBuildTarget ==
69+ BuildTarget . tvOS ) && Google . IOSResolver . Enabled ;
6870 }
6971 }
7072
7173 static XcodeProjectPatcher ( ) {
72- // Delay initialization until the build target is iOS and the editor is not in play
73- // mode.
74+ // Delay initialization until the build target is iOS+ and the
75+ // editor is not in play mode.
7476 EditorInitializer . InitializeOnMainThread (
7577 condition : ( ) => {
76- return EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS &&
78+ return ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS ||
79+ EditorUserBuildSettings . activeBuildTarget == BuildTarget . tvOS ) &&
7780 ! EditorApplication . isPlayingOrWillChangePlaymode ;
7881 } , initializer : ( ) => {
7982 // We attempt to read the config even when the target platform isn't
80- // iOS as the project settings are surfaced in the settings window.
83+ // iOS+ as the project settings are surfaced in the settings window.
8184 Google . IOSResolver . RemapXcodeExtension ( ) ;
8285 ReadConfigOnUpdate ( ) ;
8386 PlayServicesResolver . BundleIdChanged -= OnBundleIdChanged ;
@@ -96,15 +99,19 @@ internal static void ReadConfigOnUpdate() {
9699 ReadConfig ( errorOnNoConfig : false ) ;
97100 }
98101
99- // Get the iOS bundle / application ID.
100- private static string GetIOSApplicationId ( ) {
101- return UnityCompat . GetApplicationId ( BuildTarget . iOS ) ;
102+ // Get the iOS+ bundle / application ID.
103+ private static string GetIosPlusApplicationId ( ) {
104+ if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . tvOS ) {
105+ return UnityCompat . GetApplicationId ( BuildTarget . tvOS ) ;
106+ } else {
107+ return UnityCompat . GetApplicationId ( BuildTarget . iOS ) ;
108+ }
102109 }
103110
104111 // Check the editor environment on the first update after loading this
105112 // module.
106113 private static void CheckConfiguration ( ) {
107- CheckBundleId ( GetIOSApplicationId ( ) ) ;
114+ CheckBundleId ( GetIosPlusApplicationId ( ) ) ;
108115 CheckBuildEnvironment ( ) ;
109116 }
110117
@@ -115,9 +122,9 @@ internal static void ReadConfig(bool errorOnNoConfig = true, string filename = n
115122 ReadConfigInternal ( errorOnNoConfig , filename : filename ) ;
116123 } catch ( Exception exception ) {
117124 // FileNotFoundException and TypeInitializationException can be
118- // thrown *before* ReadConfigInternal is entered if the iOS Xcode
125+ // thrown *before* ReadConfigInternal is entered if the iOS+ Xcode
119126 // assembly can't be loaded so we catch them here and only report
120- // a warning if this module is enabled and iOS is the selected
127+ // a warning if this module is enabled and iOS+ is the selected
121128 // platform.
122129 if ( exception is FileNotFoundException ||
123130 exception is TypeInitializationException ) {
@@ -158,11 +165,13 @@ internal static Dictionary<string, string> GetConfig() {
158165 return configValues ;
159166 }
160167
161- // Verify that the build environment *really* supports iOS.
168+ // Verify that the build environment *really* supports iOS+ .
162169 private static void CheckBuildEnvironment ( ) {
163- // If iOS is the selected build target but we're not on a OSX machine
164- // report an error as pod installation will fail among other things.
165- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS &&
170+ // If iOS+ is the selected build target but we're not on a OSX
171+ // machine report an error as pod installation will fail among other
172+ // things.
173+ BuildTarget buildTarget = EditorUserBuildSettings . activeBuildTarget ;
174+ if ( ( buildTarget == BuildTarget . iOS || buildTarget == BuildTarget . tvOS ) &&
166175 Application . platform == RuntimePlatform . WindowsEditor ) {
167176 Debug . LogError ( DocRef . IOSNotSupportedOnWindows ) ;
168177 }
@@ -173,7 +182,7 @@ private static void OnBundleIdChanged(
173182 object sender ,
174183 PlayServicesResolver . BundleIdChangedEventArgs args ) {
175184 ReadConfig ( errorOnNoConfig : false ) ;
176- CheckBundleId ( GetIOSApplicationId ( ) ) ;
185+ CheckBundleId ( GetIosPlusApplicationId ( ) ) ;
177186 }
178187
179188 // Check the bundle ID
@@ -213,10 +222,16 @@ private static string CheckBundleId(string bundleId,
213222 "Cancel" ,
214223 selectedBundleId => {
215224 if ( ! String . IsNullOrEmpty ( selectedBundleId ) ) {
216- // If we have a valid value, the user hit apply.
217- UnityCompat . SetApplicationId ( BuildTarget . iOS , selectedBundleId ) ;
218- Measurement . ReportWithBuildTarget ( "bundleidmismatch/apply" , null ,
219- "Mismatched Bundle ID: Apply" ) ;
225+ switch ( EditorUserBuildSettings . activeBuildTarget ) {
226+ case BuildTarget . iOS :
227+ UnityCompat . SetApplicationId ( BuildTarget . iOS , selectedBundleId ) ;
228+ break ;
229+ case BuildTarget . tvOS :
230+ UnityCompat . SetApplicationId ( BuildTarget . tvOS , selectedBundleId ) ;
231+ break ;
232+ default :
233+ throw new Exception ( "unsupported iOS+ version" ) ;
234+ }
220235 } else {
221236 Measurement . ReportWithBuildTarget ( "bundleidmismatch/cancel" , null ,
222237 "Mismatched Bundle ID: Cancel" ) ;
@@ -238,7 +253,7 @@ private static string CheckBundleId(string bundleId,
238253 private static void OnPostprocessAllAssets (
239254 string [ ] importedAssets , string [ ] deletedAssets ,
240255 string [ ] movedAssets , string [ ] movedFromPath ) {
241- // We track the config file state even when the target isn't iOS
256+ // We track the config file state even when the target isn't iOS+
242257 // as the project settings are surfaced in the settings window.
243258 if ( ! Enabled ) return ;
244259 bool configFilePresent = false ;
@@ -251,7 +266,7 @@ private static void OnPostprocessAllAssets(
251266 if ( configFilePresent ) {
252267 spamguard = false ; // Reset our spamguard to show a dialog.
253268 ReadConfig ( errorOnNoConfig : false ) ;
254- CheckBundleId ( GetIOSApplicationId ( ) ) ;
269+ CheckBundleId ( GetIosPlusApplicationId ( ) ) ;
255270 }
256271 }
257272
@@ -283,7 +298,7 @@ internal static string FindConfig(bool errorOnNoConfig = true) {
283298 GOOGLE_SERVICES_INFO_PLIST_FILE , Link . IOSAddApp ) ) ;
284299 }
285300 } else if ( files . Length > 1 ) {
286- var bundleId = GetIOSApplicationId ( ) ;
301+ var bundleId = GetIosPlusApplicationId ( ) ;
287302 string selectedBundleId = null ;
288303 // Search files for the first file matching the project's bundle identifier.
289304 foreach ( var filename in files ) {
@@ -314,7 +329,9 @@ internal static string FindConfig(bool errorOnNoConfig = true) {
314329 internal static void OnPostProcessAddGoogleServicePlist (
315330 BuildTarget buildTarget , string pathToBuiltProject ) {
316331 if ( ! Enabled ) return ;
317- Measurement . analytics . Report ( "ios/xcodepatch" , "iOS Xcode Project Patcher: Start" ) ;
332+ string platform = ( buildTarget == BuildTarget . iOS ) ? "iOS" : "tvOS" ;
333+ Measurement . analytics . Report ( "ios/xcodepatch" ,
334+ platform + " Xcode Project Patcher: Start" ) ;
318335 AddGoogleServicePlist ( buildTarget , pathToBuiltProject ) ;
319336 }
320337
@@ -331,7 +348,7 @@ internal static void AddGoogleServicePlist(
331348 return ;
332349 }
333350
334- CheckBundleId ( GetIOSApplicationId ( ) , promptUpdate : false ) ;
351+ CheckBundleId ( GetIosPlusApplicationId ( ) , promptUpdate : false ) ;
335352
336353 // Copy the config file to the Xcode project folder.
337354 string configFileBasename = Path . GetFileName ( configFile ) ;
0 commit comments