본문 바로가기
개발/C#

유니티 C# 애플 로그인 Sign ln with Apple Login 간단 구현

by SPNK 2022. 8. 17.
반응형

애플 SDK 설치

 

Release Sign in with Apple Unity Plugin v1.4.2 · lupidan/apple-signin-unity

Changed Handles empty NSPersonNameComponents sent by Apple when not requesting a name, to be nil natively. Updated MacOSAppleAuthManager.bundle with the updated native code Removed Removes FixSe...

github.com

 

  • 코드 작성
using System.Collections;
using System.Text;
#if UNITY_IOS
using AppleAuth;
using AppleAuth.Native;
using AppleAuth.Enums;
using AppleAuth.Interfaces;
using AppleAuth.Extensions;
#endif
using UnityEngine;

public class AppleLogin : MonoBehaviour
{
#if UNITY_IOS
    private const string AppleUserIdKey = "AppleUserId";
    private IAppleAuthManager _appleAuthManager;
#endif

    void Awake()
    {
#if UNITY_IOS
        IOSActivate();
#endif
    }


#if UNITY_IOS
    private void IOSActivate() //애플 로그인 초기화
    {
        if (AppleAuthManager.IsCurrentPlatformSupported)
        {
            var deserializer = new PayloadDeserializer();
            _appleAuthManager = new AppleAuthManager(deserializer);
        }
        StartCoroutine(AppleAuthUpdate());
    }
    
    IEnumerator AppleAuthUpdate()
    {
        while (true)
        {
            _appleAuthManager?.Update();
            yield return null;
        }
    }
#endif


#if UNITY_IOS
    public void OnClickAppleLogin() //애플 로그인 버튼
    {
        Debug.Log("애플 로그인 시도");
        SignInWithApple();
    }

    void SignInWithApple()
    {
        var loginArgs = new AppleAuthLoginArgs(LoginOptions.IncludeEmail | LoginOptions.IncludeFullName);

        _appleAuthManager.LoginWithAppleId(
            loginArgs,
            credential =>
            {
                Debug.Log("Apple Login Success!");
            }, error =>
            {
                var authorizationErrorCode = error.GetAuthorizationErrorCode();
            });
    }

#endif
}
반응형

댓글