Skip to content

Commit

Permalink
Merge pull request #5 from ccl2020/chuanlong/fix_comments
Browse files Browse the repository at this point in the history
Address author comments
  • Loading branch information
ChuanlongChen committed Apr 22, 2024
2 parents 78df98c + ed857f6 commit 9dc825b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 70 deletions.
1 change: 0 additions & 1 deletion AppleAuth/Native/iOS/AppleAuthManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ - (ASPresentationAnchor) presentationAnchorForAuthorizationController:(ASAuthori
#else
return nil;
#endif

}

#endif
Expand Down
1 change: 0 additions & 1 deletion AppleAuth/Native/iOS/AppleAuthSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ + (NSDictionary *) loginResponseDictionaryForAppleIdCredentialDictionary:(NSDict
return [result copy];
}


// IOS/TVOS 9.0 | MACOS 10.11 | VISIONOS 1.0
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000 || __TV_OS_VERSION_MAX_ALLOWED >= 90000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 || __VISION_OS_VERSION_MAX_ALLOWED >= 10000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,49 @@
using AppleAuth.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

#if UNITY_XCODE_EXTENSIONS_AVAILABLE
using UnityEditor.iOS.Xcode;
#endif

namespace AppleAuthSample.Editor {
public static class SignInWithApplePostprocessor {
private const int CallOrder = 1;
namespace AppleAuthSample.Editor
{
public static class SignInWithApplePostprocessor
{
private const int CallOrder = 1;

[PostProcessBuild(CallOrder)]
public static void OnPostProcessBuild(BuildTarget target, string path) {
if (target == BuildTarget.iOS || target == BuildTarget.tvOS || target == BuildTarget.VisionOS) {
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
string projectPath = PBXProject.GetPBXProjectPath(path);
if (target == BuildTarget.VisionOS) {

// This is a temporary fix for the Unity Editor's bug:
// After switch to VisionOS platform the projectPath is still "xx/Unity-iPhone.xcodeproj/project.pbxproj",
// while the expected path is "xx/Unity-VisionOS.xcodeproj/project.pbxproj",
projectPath = projectPath.Replace("Unity-iPhone.xcodeproj", "Unity-VisionOS.xcodeproj");
}
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
#else
[PostProcessBuild(CallOrder)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS || target == BuildTarget.tvOS)
{
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
var projectPath = PBXProject.GetPBXProjectPath(path);
#if UNITY_2022_3_OR_LATER
if (target == BuildTarget.VisionOS) {
// This is a temporary fix for the Unity Editor's bug:
// After switch to VisionOS platform the projectPath is still "xx/Unity-iPhone.xcodeproj/project.pbxproj",
// while the expected path is "xx/Unity-VisionOS.xcodeproj/project.pbxproj",
projectPath = projectPath.Replace("Unity-iPhone.xcodeproj", "Unity-VisionOS.xcodeproj");
}
#endif
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
#else
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
#endif
} else if (target == BuildTarget.StandaloneOSX) {
AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path);
}
#endif
#endif
}
else if (target == BuildTarget.StandaloneOSX)
{
AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path);
}
}
}
}
}
69 changes: 30 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ openupm add com.lupidan.apple-signin-unity

![Import detail](./Img/ImportPlugin.png)

## Plugin setup (iOS/tvOS/visionOS)
## Plugin setup (iOS/tvOS)

To be able to use Apple's platform and framework for Authenticating with an Apple ID, we need to set up our Xcode project. Two different options are available to set up the entitlements required to enable Apple ID authentication with the iOS SDK.

Expand All @@ -148,51 +148,32 @@ The provided extension method is `AddSignInWithAppleWithCompatibility`. It accep

Sample code:
```csharp
#if UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS
#define UNITY_XCODE_EXTENSIONS_AVAILABLE
#endif

using AppleAuth.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
using UnityEditor.iOS.Xcode;
#endif

namespace AppleAuthSample.Editor {
public static class SignInWithApplePostprocessor {
private const int CallOrder = 1;

[PostProcessBuild(CallOrder)]
public static void OnPostProcessBuild(BuildTarget target, string path) {
if (target == BuildTarget.iOS || target == BuildTarget.tvOS || target == BuildTarget.VisionOS) {
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
string projectPath = PBXProject.GetPBXProjectPath(path);
if (target == BuildTarget.VisionOS) {
// Unity's bug:
// After switch to VisionOS platform the projectPath is still "xx/Unity-iPhone.xcodeproj/project.pbxproj",
// while the expected path is "xx/Unity-VisionOS.xcodeproj/project.pbxproj",
// temporary fix:
projectPath = projectPath.Replace("Unity-iPhone.xcodeproj", "Unity-VisionOS.xcodeproj");
}
public static class SignInWithApplePostprocessor
{
[PostProcessBuild(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.iOS)
return;

var projectPath = PBXProject.GetPBXProjectPath(path);

// Adds entitlement depending on the Unity version used
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
#else
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
}
}
}
}

```

### Manual entitlements setup
Expand Down Expand Up @@ -235,6 +216,16 @@ The `AuthenticationServices.framework` should be added as Optional, to support p

The provided extension method uses reflection to integrate with the current tools Unity provides. It has been tested with Unity 2018.x and 2019.x. But if it fails on your particular Unity version, feel free to open a issue, specifying the Unity version.

## Plugin setup (visionOS)

On visionOS, the setup is pretty much the same as the iOS/tvOS setup.
However, due to how Unity's visionOS project is exported, you need to adapt the Postprocess code to find the proper xcode project filename:

if (target == BuildTarget.VisionOS)
{
projectPath = projectPath.Replace("Unity-iPhone.xcodeproj", "Unity-VisionOS.xcodeproj");
}

## Plugin setup (macOS)

An unsigned precompiled `.bundle` file is available. The precompiled `.bundle` should support both architectures: Intel `x86_64` & Apple Silicon `arm64`(Experimental). The bundle should be automatically included in your macOS builds.
Expand Down

0 comments on commit 9dc825b

Please sign in to comment.