You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.9 KiB
100 lines
3.9 KiB
4 years ago
|
//
|
||
|
// 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
|