Files
keyboard/keyBoard/Class/Manager/AppleSignInManager.h

38 lines
1.4 KiB
C
Raw Normal View History

2025-10-30 14:29:11 +08:00
// AppleSignInManager.h
// 封装“用 Apple 登录”逻辑
#import <Foundation/Foundation.h>
#import <AuthenticationServices/AuthenticationServices.h>
@class UIViewController;
NS_ASSUME_NONNULL_BEGIN
/// Apple 登录回调结果
typedef void (^KBAppleSignInCompletion)(ASAuthorizationAppleIDCredential * _Nullable credential, NSError * _Nullable error);
/// AppleSignInManager 集中管理 Apple 登录流程与代理回调
@interface AppleSignInManager : NSObject <ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
/// 单例便捷访问
+ (instancetype)shared;
/// 发起 Apple 登录
/// - 参数说明:
/// - presenting: 用于呈现授权界面的控制器
/// - completion: 主线程回调,返回凭证或错误
- (void)signInFromViewController:(UIViewController *)presenting completion:(KBAppleSignInCompletion)completion;
/// 根据已存储的 userIdentifier 检查凭证状态
/// 返回ASAuthorizationAppleIDProviderCredentialAuthorized/Revoked/NotFound
- (void)checkCredentialStateWithCompletion:(void(^)(ASAuthorizationAppleIDProviderCredentialState state))completion;
/// 最近一次成功登录的 userIdentifier已持久化
@property (nonatomic, readonly, nullable) NSString *storedUserIdentifier;
/// 本地登出:清除已存储的 userIdentifier不会向苹果撤销授权
- (void)signOut;
@end
NS_ASSUME_NONNULL_END