Search Unity

Adding Apple Sign-In Capabilities and framework dependencies on PostProcessing

Discussion in 'iOS and tvOS' started by pistoleta, Feb 7, 2020.

  1. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Hi guys. I'm using the official unity asset here . And in order to make it work the documentation describes how to do 3 easy steps on the Xcode project:

    1- In Target Settings the “Sign in with Apple” capability must be added. Click the button labeled “+ Capability” and choose “Sign in with Apple”
    2- The AuthenticationServices framework must be added to the project.
    3- Find the AuthenticationServices framework and change the Status from “Required” to “Optional”.

    Now, I'm trying to do these steps in the OnProcessBuild event but they don't seem to be working:

    Code (CSharp):
    1.   [PostProcessBuild(1)]
    2. [PostProcessBuild(1)]
    3.     public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    4.     {
    5.         if (buildTarget != BuildTarget.iOS)
    6.             return;
    7.      
    8.         string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
    9.         ProjectCapabilityManager projCapability = new ProjectCapabilityManager(projPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
    10.         projCapability.AddSignInWithApple();
    11.         projCapability.WriteToFile();
    Im trying to follow the Capability manager instructions here

    Also, since the authentication services are already included in my project im trying to remove them first to add them later but not even that is working, this is my code:

    Code (CSharp):
    1. PBXProject proj = new PBXProject();
    2.         string pbxFilename = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
    3.         proj.ReadFromFile (pbxFilename);
    4.         string targetName = PBXProject.GetUnityTargetName ();
    5.         string guid = proj.TargetGuidByName (targetName);
    6.         proj.RemoveFrameworkFromProject(guid, "AuthenticationServices");
    7.  
    Could you give me a bit of light here please? I dont know what else I can try.
    By the way the OnPostProcessBuild method is getting called and I'm not getting any exception.
    I'm using Unity 2019.2.20f1

    Thanks for your attention,
    pistoleta
     
  2. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
  3. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I add the capability like this.

    Code (CSharp):
    1.     static void AddCapabilities(string pathToBuiltProject)
    2.     {
    3.         string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
    4.         ProjectCapabilityManager projCapability = new ProjectCapabilityManager(projPath, "mygame.entitlements", "Unity-iPhone");
    5.         projCapability.AddSignInWithApple();
    6.         projCapability.WriteToFile();
    7.     }
    8.  
    I use egoXcode to add the framework.
     
  4. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Nothing, I copied your code and it doesn't work for me, but I just realized, I'm working with the xcworkspace not the xcodeproj file, maybe has something to do with that?

    Thanks again
     
  5. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I have an .xcworkspace and .xcodeproj. Did you use the correct entitlements filename?

    And yes, egoXcode does still work. It's no longer supported and updated though, but is now free, with source code I believe.
     
  6. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    388
    I had to do it like this:
    Code (CSharp):
    1. string mainGuid = project.GetUnityMainTargetGuid();
    2. string frameworkGuid = project.GetUnityFrameworkTargetGuid();
    3. var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, mainGuid);
    4. manager.AddSignInWithAppleWithCompatibility(frameworkGuid);
    5. manager.WriteToFile();
    This variant did not work, although the docs mention it as an alternative:
    Code (CSharp):
    1. PBXProject.AddCapability
     
    sandolkakos likes this.
  7. maggie03230

    maggie03230

    Joined:
    May 23, 2017
    Posts:
    2
    Thanks for your tip!
    I used only unity api, and changed one line to make it worked.
    unity version: 2018.4.23f1
    Code (CSharp):
    1.  
    2. public static void OnPostProcessBuild2(BuildTarget buildTarget, string path) {
    3.     string projPath = PBXProject.GetPBXProjectPath(path);
    4.     // changed
    5.     ProjectCapabilityManager projCapability = new ProjectCapabilityManager(projPath, "Unity-iPhone/myAppName.entitlements", "Unity-iPhone");
    6.     projCapability.AddSignInWithApple();
    7.     projCapability.WriteToFile();
    8. }
    9.  
    10.  
     
  8. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285
    That is the only way I could make it work. Thanks for sharing it, @waldgeist

    I can confirm `PBXProject.AddCapability` does not work using the Unity 2022.2.7f1, and I don't understand why. :(
     
  9. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    do you know how to do "You need to import the AuthenticationServices.framework library in the Build Phases->Link Binary with Libraries. If you are targeting older iOS versions, mark the library as Optional."
    with post processing scripts ?
    it's from the new apple sign in package
    https://github.com/lupidan/apple-signin-unity
     
  10. dyguests

    dyguests

    Joined:
    May 4, 2015
    Posts:
    16
    It works for me. TKS!!!