Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Official Upcoming Game Center entitlement requirement by Apple

Discussion in 'iOS and tvOS' started by Evaldas_Unity, Aug 8, 2023.

  1. Evaldas_Unity

    Evaldas_Unity

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    69
    We are aware that ProjectCapabilityManager.AddGameCenter() is not adding the soon to be required Game Center entitlement

    This has been fixed but hasn't landed in all of the streams yet, so here are a few workarounds for those waiting:
    • Simply editing the exported project with XCode to include the capability and entitlement - this should work for most simple use cases, but is fully manual.
    • Making a PostprocessBuild script that adds it - a little more involved, I've tried to make it as generic as possible, but it might require editing to fully fit your needs. Example script below:
    (*note: script needs to be added to "Editor" folder)

    Code (CSharp):
    1. using System;
    2. using System.IO;
    3. using UnityEditor;
    4. using UnityEditor.Build;
    5. using UnityEditor.Build.Reporting;
    6. using UnityEditor.iOS.Xcode;
    7. using UnityEngine;
    8. public class CapabilityPostprocessBuild : IPostprocessBuildWithReport
    9. {
    10.     public int callbackOrder => 999;
    11.     public void OnPostprocessBuild(BuildReport report)
    12.     {
    13.         Debug.Log("PostprocessBuild");
    14.         OnPostprocessBuild(report.summary.platform, report.summary.outputPath);
    15.     }
    16.  
    17.     public void OnPostprocessBuild(BuildTarget buildTarget, string path)
    18.     {
    19.         if (buildTarget == BuildTarget.iOS)
    20.         {
    21.             Debug.Log($"ProjectPath: {path}");
    22.          
    23.             string projPath = PBXProject.GetPBXProjectPath(path);
    24.             Debug.Log($"PBXProjectPath: {projPath}");
    25.            
    26.             PBXProject proj = new PBXProject();
    27.             proj.ReadFromFile(projPath);
    28.          
    29.             var mainTarget = proj.GetUnityMainTargetGuid();
    30.             // Get path to entitlement file (if one was created by Unity) using the Main Target. If the file doesn't exist, we make our own
    31.             string entitlementPath = proj.GetEntitlementFilePathForTarget(mainTarget) ?? $"{path}/Entitlements.entitlements";
    32.             Debug.Log($"EntitlementFilePath: {entitlementPath}");
    33.          
    34.             // Create a new entitlement file if one doesn't exist and populate it with the template
    35.             if(!File.Exists(entitlementPath))
    36.             {
    37.                 File.WriteAllText(entitlementPath, _entitlementsTemplate);
    38.             }
    39.          
    40.             PlistDocument entitlementsDoc = new PlistDocument();
    41.             entitlementsDoc.ReadFromString(File.ReadAllText(entitlementPath));
    42.          
    43.             // Add the Game Center capability to the root dict of the entitlements file
    44.             PlistElementDict entitlementDict = entitlementsDoc.root;
    45.             entitlementDict.SetBoolean("com.apple.developer.game-center", true);
    46.             File.WriteAllText(entitlementPath, entitlementsDoc.WriteToString());
    47.          
    48.             Debug.Log("Done");
    49.         }
    50.     }
    51.  
    52.     private static readonly string _entitlementsTemplate =
    53. @"<?xml version=""1.0"" encoding=""UTF-8""?>
    54. <!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
    55. <plist version=""1.0"">
    56.    <dict>
    57.    </dict>
    58. </plist>";  
    59. }
    These workarounds won't be needed once the fix lands in the streams. You can look out for it by keeping an eye on mentions of fix for UUM-44172 in the release notes or on the issue tracker
     
  2. xyome

    xyome

    Joined:
    Jul 4, 2014
    Posts:
    9
    If you already have an entitlement file generated this script will not work. Line 31 should be replaced by something like this:

    string entitlementPath = proj.GetEntitlementFilePathForTarget(mainTarget) ?? "Entitlements.entitlements";
    entitlementPath = Path.Combine(path, entitlementPath);
     
    Evaldas_Unity likes this.
  3. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    Issue Tracker says fixed in 2021.3.30f1... but that is not out yet. Any ETA on that release?
     
  4. Evaldas_Unity

    Evaldas_Unity

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    69
    No promises, but I think the release window for that particular version is somewhere around September 1st.
    I think that LTS is on monthly release so it's about time from the last one
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    2021.3.30f1 is out, but I don't see anything in the release notes about this? (haven't checked to see what actually happens yet)
     
  6. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    It's in the Release Notes (search for GameCenter). Haven't been able to verify -- when I updated Unity Cloud Build to use .30 (from .29), the archiving is failing for some reason.
     
    AcidArrow likes this.
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    Ah , it is indeed there, don’t know how I missed it.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    I just tried it, it adds the entitlement but it doesn't add the capability (nor the Game Controller one), so I still need to manually fix them.
     
  9. nbasaran

    nbasaran

    Joined:
    Jul 18, 2018
    Posts:
    3
    We're having the same issue. How have you overcome the issue by adding it manually though? Thanks
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    Yeah I'm doing everything manually in Xcode as I did before the fix.