小说绘上架版本
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// TFAppleSignManager.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/4.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class TFUserInfoManager;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TFAppleSignState) {
|
||||
TFAppleSignStateLogin,
|
||||
TFAppleSignStateBinding
|
||||
};
|
||||
|
||||
@protocol TFAppleSignDelegate <NSObject>
|
||||
@optional
|
||||
|
||||
- (void)appleSignResponseSuccess:(TFUserInfoManager *)userData;
|
||||
|
||||
- (void)appleSignResponseFail:(NSString *)error;
|
||||
@end
|
||||
|
||||
@interface TFAppleSignManager : NSObject
|
||||
|
||||
@property (nonatomic ,weak) id <TFAppleSignDelegate> delegate;
|
||||
|
||||
interface_singleton
|
||||
|
||||
- (void)tunedUpAppleSignWithState:(TFAppleSignState)state API_AVAILABLE(ios(13.0));
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// TFAppleSignManager.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/4.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFAppleSignManager.h"
|
||||
#import <AuthenticationServices/AuthenticationServices.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface TFAppleSignManager ()<ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFAppleSignManager
|
||||
|
||||
implementation_singleton(TFAppleSignManager)
|
||||
|
||||
- (void)tunedUpAppleSignWithState:(TFAppleSignState)state
|
||||
{
|
||||
ASAuthorizationAppleIDProvider *provider = [[ASAuthorizationAppleIDProvider alloc] init];
|
||||
ASAuthorizationAppleIDRequest *request = [provider createRequest];
|
||||
request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
|
||||
|
||||
ASAuthorizationController *authorization = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
|
||||
authorization.delegate = self;
|
||||
authorization.presentationContextProvider = self;
|
||||
[authorization performRequests];
|
||||
}
|
||||
|
||||
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0))
|
||||
{
|
||||
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
|
||||
return app.window;
|
||||
}
|
||||
|
||||
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0))
|
||||
{
|
||||
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
|
||||
[self requestTouristsLogin];
|
||||
}
|
||||
}
|
||||
|
||||
// 游客登录请求
|
||||
- (void)requestTouristsLogin
|
||||
{
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusLoading promptTitle:TFLocalizedString(@"正在登录")];
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Tourists_Login parameters:@{@"udid":[TFUtilsHelper getUDID]} model:TFUserInfoManager.class success:^(BOOL isSuccess, TFUserInfoManager * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
[TFPromptManager hiddenAlert];
|
||||
if (isSuccess) {
|
||||
[weakSelf appleSignResponseSuccess:t_model];
|
||||
} else {
|
||||
[weakSelf appleSignResponseFail:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager hiddenAlert];
|
||||
[weakSelf appleSignResponseFail:error.localizedFailureReason ?: TFLocalizedString(@"登录失败")];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0))
|
||||
{
|
||||
NSString *errorMsg = nil;
|
||||
|
||||
switch (error.code) {
|
||||
case ASAuthorizationErrorCanceled:
|
||||
errorMsg = TFLocalizedString(@"您已取消授权");
|
||||
break;
|
||||
case ASAuthorizationErrorFailed:
|
||||
errorMsg = TFLocalizedString(@"授权请求失败");
|
||||
break;
|
||||
case ASAuthorizationErrorInvalidResponse:
|
||||
errorMsg = TFLocalizedString(@"授权请求响应无效");
|
||||
break;
|
||||
case ASAuthorizationErrorNotHandled:
|
||||
errorMsg = TFLocalizedString(@"未能处理授权请求");
|
||||
break;
|
||||
case ASAuthorizationErrorUnknown:
|
||||
errorMsg = TFLocalizedString(@"授权失败");
|
||||
break;
|
||||
}
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:errorMsg];
|
||||
}
|
||||
|
||||
- (void)appleSignResponseSuccess:(TFUserInfoManager *)userData
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(appleSignResponseSuccess:)]) {
|
||||
[self.delegate appleSignResponseSuccess:userData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)appleSignResponseFail:(NSString *)error
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(appleSignResponseFail:)]) {
|
||||
[self.delegate appleSignResponseFail:error ? : @""];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user