Search Unity

Sign In With Apple, Cloud Build Version

Discussion in 'iOS and tvOS' started by JamesA24, Mar 27, 2020.

  1. JamesA24

    JamesA24

    Joined:
    Sep 6, 2018
    Posts:
    28
    Hey everyone,

    I'm currently in progress of setting up Sign In With Apple. I don't work on a Mac and therefore I don't have XCode available. For this to work, I need to add the capability to the entitlements, and add a AuthenticationServices framework to my list of frameworks.

    I was using: https://blogs.unity3d.com/2019/09/19/support-for-apple-sign-in/ as a reference initially.

    However, Unity doesn't like to provide documentation on how to do such things for Cloud Build.

    I've tried a few builds now and it seems the AuthenticationServices framework is being added correctly. But I don't think the capability is being added correctly.

    When attempting to sign in for apple, I get this error: com.apple.AuthenticationServices.AuthorizationError error 1000.

    We use One Signal as well, so I've been trying to reference a bit of how they get themselves organized for the IOS PostBuild as well. So far, hasn't been working out.

    I've posted the IOSPostBuild script I'm using. This is a file that I didn't start, but another person started that I work with. The only changes I've made involve AuthenticationServices.framework and the sign in capability.

    Any information or help would be appreciated!

    Code (CSharp):
    1. public class IOSPostBuild
    2. {
    3.     public static readonly string DEFAULT_PROJECT_TARGET_NAME = "Unity-iPhone";
    4.  
    5.     [PostProcessBuild(1)]
    6.     public static void OnPostProcess(BuildTarget buildTarget, string buildPath)
    7.     {
    8. #if UNITY_IOS
    9.         if (buildTarget == BuildTarget.iOS)
    10.         {
    11.             //UPDATE THE PLIST
    12.             string plistPath = buildPath + "/Info.plist";
    13.             PlistDocument plist = new PlistDocument();
    14.             plist.ReadFromString(File.ReadAllText(plistPath));
    15.             PlistElementDict rootDict = plist.root;
    16.             rootDict.SetString("NSCameraUsageDescription", "Improve the quality of service of this product");
    17.             rootDict.SetString("NSLocationAlwaysUsageDescription", "Improve the quality of service of this product");
    18.             rootDict.SetString("NSLocationWhenInUseUsageDescription", "Improve the quality of service of this product");
    19.  
    20.             rootDict.SetBoolean("NSAllowsArbitraryLoadsForMedia", true);
    21.             rootDict.SetBoolean("NSAllowsArbitraryLoadsInWebContent", true);
    22.  
    23.             string exitsOnSuspendKey = "UIApplicationExitsOnSuspend";
    24.             if(rootDict.values.ContainsKey(exitsOnSuspendKey))
    25.             {
    26.                 rootDict.values.Remove(exitsOnSuspendKey);
    27.             }
    28.  
    29.             PlistElementArray bgModes = rootDict.CreateArray("UIBackgroundModes");
    30.             bgModes.AddString("remote-notification");
    31.             File.WriteAllText(plistPath, plist.WriteToString());
    32.  
    33.             // UPDATE THE  PBXProject
    34.             var projectPath = PBXProject.GetPBXProjectPath(buildPath);
    35.  
    36.             var project = new PBXProject();
    37.             project.ReadFromFile(projectPath);
    38.  
    39.             var mainTargetName = DEFAULT_PROJECT_TARGET_NAME;
    40.             var mainTargetGUID = project.GetUnityMainTargetGuid();
    41.             var unityFrameworkGUID = project.GetUnityFrameworkTargetGuid();
    42.  
    43.             Dictionary<string, bool> frameworks = new Dictionary<string, bool>
    44.             {
    45.                 { "Security.framework", false },
    46.                 { "AuthenticationServices.framework", true }
    47.             };
    48.  
    49.             foreach (KeyValuePair<string, bool> framework in frameworks)
    50.             {
    51.                 project.AddFrameworkToProject(unityFrameworkGUID , framework.Key, framework.Value);
    52.             };
    53.  
    54.             project.AddCapability(mainTargetGUID, PBXCapabilityType.SignInWithApple);
    55.             var entitlementPath = project.GetBuildPropertyForConfig(unityFrameworkGUID, "CODE_SIGN_ENTITLEMENTS");
    56.  
    57.             ProjectCapabilityManager pcm = new ProjectCapabilityManager(projectPath, entitlementPath, mainTargetName, mainTargetGUID);
    58.             pcm.AddSignInWithApple();
    59.             pcm.WriteToFile();
    60.  
    61.             project.WriteToFile(projectPath);
    62.  
    63.         }
    64. #endif
    65.     }
    66. }
     
  2. ChristianMrswordsmith

    ChristianMrswordsmith

    Joined:
    May 1, 2020
    Posts:
    6
    Did you ever solve this?
     
  3. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    I also use Cloud Build to make my iOS builds. Having the exact same issue and no idea how to fix this, or what the issue is exactly.
     
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    I am still stuck with this too but I would recommend you to

    - inspect the PList and entitlements file generated from unity local build. Copy it somewhere
    - Add capability in xcode like that video told you to do
    - Diff the cached and the result of xcode

    I suspect that it related to some key in entitlements file that xcode doing something internally more than we expect

    maybe this post was the reason : https://forum.unity.com/threads/add-sign-in-with-apple-entitlement-any-success.875566/#post-5767423
     
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    Not sure it related but I have add capability to both target

    Code (CSharp):
    1.  
    2.         foreach(var guid in new [] { proj.GetUnityMainTargetGuid(),proj.GetUnityFrameworkTargetGuid() })
    3.         {
    4.             var m = new ProjectCapabilityManager(projPath,"Unity-iPhone/Unity-iPhone.entitlements",null,guid);
    5.             m.AddSignInWithApple();
    6.             m.AddInAppPurchase();
    7.             m.WriteToFile();
    8.         }