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;
|
|
|
|
|
|
|
2025-10-30 14:35:06 +08:00
|
|
|
|
/// 使用给定 userIdentifier 检查凭证状态(推荐:从服务端返回的 userIdentifier)
|
|
|
|
|
|
- (void)checkCredentialStateForUserID:(NSString *)userID completion:(void(^)(ASAuthorizationAppleIDProviderCredentialState state))completion;
|
|
|
|
|
|
|
2025-10-30 14:29:11 +08:00
|
|
|
|
/// 最近一次成功登录的 userIdentifier(已持久化)
|
|
|
|
|
|
@property (nonatomic, readonly, nullable) NSString *storedUserIdentifier;
|
|
|
|
|
|
|
|
|
|
|
|
/// 本地登出:清除已存储的 userIdentifier(不会向苹果撤销授权)
|
|
|
|
|
|
- (void)signOut;
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|