小说绘上架版本
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// TFTencentPermissionsManager.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/4.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TFTencentPermissionsType) {
|
||||
TFTencentPermissionsTypeLogin,
|
||||
TFTencentPermissionsTypeBinding
|
||||
};
|
||||
|
||||
@protocol TFTencentPermissionsDelegate <NSObject>
|
||||
@optional
|
||||
// 登录成功
|
||||
- (void)tencentPermissionsSuccess:(TFUserInfoManager *)userData;
|
||||
|
||||
// 登录失败
|
||||
- (void)tencentPermissionsFail:(NSString *)error;
|
||||
@end
|
||||
|
||||
@interface TFTencentPermissionsManager : NSObject
|
||||
|
||||
@property (nonatomic ,weak) id <TFTencentPermissionsDelegate> delegate;
|
||||
|
||||
interface_singleton
|
||||
|
||||
- (void)tencentPermissionsType:(TFTencentPermissionsType)type;
|
||||
|
||||
+ (BOOL)isInstallTencent;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// TFTencentPermissionsManager.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/4.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFTencentPermissionsManager.h"
|
||||
#import <ShareSDK/ShareSDK.h>
|
||||
|
||||
@interface TFTencentPermissionsManager ()
|
||||
|
||||
@property (nonatomic ,assign) TFTencentPermissionsType *permissionsType;
|
||||
@end
|
||||
|
||||
@implementation TFTencentPermissionsManager
|
||||
|
||||
implementation_singleton(TFTencentPermissionsManager)
|
||||
|
||||
- (void)tencentPermissionsType:(TFTencentPermissionsType)type
|
||||
{
|
||||
WS(weakSelf)
|
||||
[ShareSDK authorize:SSDKPlatformTypeQQ settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
|
||||
|
||||
if (state == SSDKResponseStateSuccess) {
|
||||
if (type == TFTencentPermissionsTypeLogin) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusLoading promptTitle:TFLocalizedString(@"QQ登录中")];
|
||||
}
|
||||
|
||||
if (type == TFTencentPermissionsTypeBinding) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusLoading promptTitle:TFLocalizedString(@"正在获取QQ信息")];
|
||||
}
|
||||
|
||||
NSDictionary *params = @{
|
||||
@"access_token" : user.credential.token
|
||||
};
|
||||
|
||||
if (type == TFTencentPermissionsTypeLogin) {
|
||||
|
||||
[TFNetworkTools POST:QQ_Login parameters:params model:TFUserInfoManager.class success:^(BOOL isSuccess, TFUserInfoManager *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
if (isSuccess) {
|
||||
[weakSelf tencentRequestSuccess:t_model];
|
||||
return;
|
||||
}
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[weakSelf tencentRequestFail:TFLocalizedString(@"QQ登录失败")];
|
||||
}];
|
||||
return ;
|
||||
}
|
||||
|
||||
if (type == TFTencentPermissionsTypeBinding) {
|
||||
[TFNetworkTools POST:QQ_Binding parameters:params model:TFUserInfoManager.class success:^(BOOL isSuccess, TFUserInfoManager *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
if (isSuccess) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"QQ绑定成功")];
|
||||
[weakSelf tencentRequestSuccess:t_model];
|
||||
return ;
|
||||
}
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[weakSelf tencentRequestFail:TFLocalizedString(@"QQ绑定失败")];
|
||||
}];
|
||||
return;
|
||||
}
|
||||
} else if (state == SSDKResponseStateCancel) {
|
||||
[weakSelf tencentRequestFail:TFLocalizedString(@"授权取消")];
|
||||
|
||||
} else if (state == SSDKResponseStateFail) {
|
||||
if (type == TFTencentPermissionsTypeLogin) {
|
||||
[weakSelf tencentRequestFail:TFLocalizedString(@"QQ登录失败")];
|
||||
}
|
||||
|
||||
if (type == TFTencentPermissionsTypeBinding) {
|
||||
[weakSelf tencentRequestFail:TFLocalizedString(@"QQ绑定失败")];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
+ (BOOL)isInstallTencent
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)tencentRequestSuccess:(TFUserInfoManager *)userData
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(tencentPermissionsSuccess:)]) {
|
||||
[self.delegate tencentPermissionsSuccess:userData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tencentRequestFail:(NSString *)error
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(tencentPermissionsFail:)]) {
|
||||
[self.delegate tencentPermissionsFail:error ?: @""];
|
||||
}
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user