mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-06-24 22:03:48 +08:00
Objective-C 代码格式化
This commit is contained in:
@ -3,18 +3,18 @@
|
||||
#import <TencentOpenAPI/TencentOAuth.h>
|
||||
|
||||
enum TencentScene {
|
||||
SCENE_QQ = 0,
|
||||
SCENE_QZONE = 1,
|
||||
SCENE_QQ = 0,
|
||||
SCENE_QZONE = 1,
|
||||
};
|
||||
|
||||
enum TencentRetCode {
|
||||
// 网络请求成功发送至服务器,并且服务器返回数据格式正确
|
||||
// 这里包括所请求业务操作失败的情况,例如没有授权等原因导致
|
||||
RET_SUCCESS = 0,
|
||||
// 网络异常,或服务器返回的数据格式不正确导致无法解析
|
||||
RET_FAILED = 1,
|
||||
RET_COMMON = -1,
|
||||
RET_USERCANCEL = -2,
|
||||
// 网络请求成功发送至服务器,并且服务器返回数据格式正确
|
||||
// 这里包括所请求业务操作失败的情况,例如没有授权等原因导致
|
||||
RET_SUCCESS = 0,
|
||||
// 网络异常,或服务器返回的数据格式不正确导致无法解析
|
||||
RET_FAILED = 1,
|
||||
RET_COMMON = -1,
|
||||
RET_USERCANCEL = -2,
|
||||
};
|
||||
|
||||
@interface TencentKitPlugin () <TencentSessionDelegate, QQApiInterfaceDelegate>
|
||||
@ -22,18 +22,18 @@ enum TencentRetCode {
|
||||
@end
|
||||
|
||||
@implementation TencentKitPlugin {
|
||||
FlutterMethodChannel *_channel;
|
||||
TencentOAuth *_oauth;
|
||||
FlutterMethodChannel *_channel;
|
||||
TencentOAuth *_oauth;
|
||||
}
|
||||
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
|
||||
FlutterMethodChannel *channel =
|
||||
[FlutterMethodChannel methodChannelWithName:@"v7lin.github.io/tencent_kit"
|
||||
binaryMessenger:[registrar messenger]];
|
||||
TencentKitPlugin *instance =
|
||||
[[TencentKitPlugin alloc] initWithChannel:channel];
|
||||
[registrar addApplicationDelegate:instance];
|
||||
[registrar addMethodCallDelegate:instance channel:channel];
|
||||
FlutterMethodChannel *channel =
|
||||
[FlutterMethodChannel methodChannelWithName:@"v7lin.github.io/tencent_kit"
|
||||
binaryMessenger:[registrar messenger]];
|
||||
TencentKitPlugin *instance =
|
||||
[[TencentKitPlugin alloc] initWithChannel:channel];
|
||||
[registrar addApplicationDelegate:instance];
|
||||
[registrar addMethodCallDelegate:instance channel:channel];
|
||||
}
|
||||
|
||||
static NSString *const METHOD_REGISTERAPP = @"registerApp";
|
||||
@ -72,264 +72,267 @@ static NSString *const ARGUMENT_KEY_RESULT_CREATE_AT = @"create_at";
|
||||
static NSString *const SCHEME_FILE = @"file";
|
||||
|
||||
- (instancetype)initWithChannel:(FlutterMethodChannel *)channel {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_channel = channel;
|
||||
}
|
||||
return self;
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_channel = channel;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall *)call
|
||||
result:(FlutterResult)result {
|
||||
if ([METHOD_REGISTERAPP isEqualToString:call.method]) {
|
||||
NSString *appId = call.arguments[ARGUMENT_KEY_APPID];
|
||||
NSString *universalLink = call.arguments[ARGUMENT_KEY_UNIVERSALLINK];
|
||||
if (universalLink != nil) {
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId
|
||||
andUniversalLink:universalLink
|
||||
andDelegate:self];
|
||||
if ([METHOD_REGISTERAPP isEqualToString:call.method]) {
|
||||
NSString *appId = call.arguments[ARGUMENT_KEY_APPID];
|
||||
NSString *universalLink = call.arguments[ARGUMENT_KEY_UNIVERSALLINK];
|
||||
if (universalLink != nil) {
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId
|
||||
andUniversalLink:universalLink
|
||||
andDelegate:self];
|
||||
} else {
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId andDelegate:self];
|
||||
}
|
||||
result(nil);
|
||||
} else if ([METHOD_ISINSTALLED isEqualToString:call.method]) {
|
||||
result([NSNumber numberWithBool:[TencentOAuth iphoneQQInstalled]]);
|
||||
} else if ([METHOD_LOGIN isEqualToString:call.method]) {
|
||||
[self login:call result:result];
|
||||
} else if ([METHOD_LOGOUT isEqualToString:call.method]) {
|
||||
[self logout:call result:result];
|
||||
} else if ([METHOD_SHAREMOOD isEqualToString:call.method]) {
|
||||
[self shareMood:call result:result];
|
||||
} else if ([METHOD_SHAREIMAGE isEqualToString:call.method]) {
|
||||
[self shareImage:call result:result];
|
||||
} else if ([METHOD_SHAREMUSIC isEqualToString:call.method]) {
|
||||
[self shareMusic:call result:result];
|
||||
} else if ([METHOD_SHAREWEBPAGE isEqualToString:call.method]) {
|
||||
[self shareWebpage:call result:result];
|
||||
} else {
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId andDelegate:self];
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
result(nil);
|
||||
} else if ([METHOD_ISINSTALLED isEqualToString:call.method]) {
|
||||
result([NSNumber numberWithBool:[TencentOAuth iphoneQQInstalled]]);
|
||||
} else if ([METHOD_LOGIN isEqualToString:call.method]) {
|
||||
[self login:call result:result];
|
||||
} else if ([METHOD_LOGOUT isEqualToString:call.method]) {
|
||||
[self logout:call result:result];
|
||||
} else if ([METHOD_SHAREMOOD isEqualToString:call.method]) {
|
||||
[self shareMood:call result:result];
|
||||
} else if ([METHOD_SHAREIMAGE isEqualToString:call.method]) {
|
||||
[self shareImage:call result:result];
|
||||
} else if ([METHOD_SHAREMUSIC isEqualToString:call.method]) {
|
||||
[self shareMusic:call result:result];
|
||||
} else if ([METHOD_SHAREWEBPAGE isEqualToString:call.method]) {
|
||||
[self shareWebpage:call result:result];
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)login:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
if (_oauth != nil) {
|
||||
NSString *scope = call.arguments[ARGUMENT_KEY_SCOPE];
|
||||
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
||||
[_oauth authorize:permissions];
|
||||
}
|
||||
result(nil);
|
||||
if (_oauth != nil) {
|
||||
NSString *scope = call.arguments[ARGUMENT_KEY_SCOPE];
|
||||
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
||||
[_oauth authorize:permissions];
|
||||
}
|
||||
result(nil);
|
||||
}
|
||||
|
||||
- (void)logout:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
if (_oauth != nil) {
|
||||
[_oauth logout:self];
|
||||
}
|
||||
result(nil);
|
||||
if (_oauth != nil) {
|
||||
[_oauth logout:self];
|
||||
}
|
||||
result(nil);
|
||||
}
|
||||
|
||||
- (void)shareMood:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
if (scene.intValue == SCENE_QZONE) {
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSArray *imageUris = call.arguments[ARGUMENT_KEY_IMAGEURIS];
|
||||
NSString *videoUri = call.arguments[ARGUMENT_KEY_VIDEOURI];
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
if (scene.intValue == SCENE_QZONE) {
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSArray *imageUris = call.arguments[ARGUMENT_KEY_IMAGEURIS];
|
||||
NSString *videoUri = call.arguments[ARGUMENT_KEY_VIDEOURI];
|
||||
|
||||
if (videoUri == nil || videoUri.length == 0) {
|
||||
NSMutableArray *imageDatas = [NSMutableArray array];
|
||||
if (imageUris != nil && imageUris.count > 0) {
|
||||
for (NSString *imageUri in imageUris) {
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
[imageDatas addObject:imageData];
|
||||
if (videoUri == nil || videoUri.length == 0) {
|
||||
NSMutableArray *imageDatas = [NSMutableArray array];
|
||||
if (imageUris != nil && imageUris.count > 0) {
|
||||
for (NSString *imageUri in imageUris) {
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
[imageDatas addObject:imageData];
|
||||
}
|
||||
}
|
||||
QQApiImageArrayForQZoneObject *object =
|
||||
[QQApiImageArrayForQZoneObject objectWithimageDataArray:imageDatas
|
||||
title:summary
|
||||
extMap:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
} else {
|
||||
QQApiVideoForQZoneObject *object =
|
||||
[QQApiVideoForQZoneObject objectWithAssetURL:videoUri
|
||||
title:summary
|
||||
extMap:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
}
|
||||
QQApiImageArrayForQZoneObject *object =
|
||||
[QQApiImageArrayForQZoneObject objectWithimageDataArray:imageDatas
|
||||
title:summary
|
||||
extMap:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
} else {
|
||||
QQApiVideoForQZoneObject *object =
|
||||
[QQApiVideoForQZoneObject objectWithAssetURL:videoUri
|
||||
title:summary
|
||||
extMap:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
}
|
||||
result(nil);
|
||||
result(nil);
|
||||
}
|
||||
|
||||
- (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
QQApiImageObject *object = [QQApiImageObject objectWithData:imageData
|
||||
previewImageData:nil
|
||||
title:nil
|
||||
description:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
result(nil);
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
QQApiImageObject *object = [QQApiImageObject objectWithData:imageData
|
||||
previewImageData:nil
|
||||
title:nil
|
||||
description:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
result(nil);
|
||||
}
|
||||
|
||||
- (void)shareMusic:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
NSString *title = call.arguments[ARGUMENT_KEY_TITLE];
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
NSString *musicUrl = call.arguments[ARGUMENT_KEY_MUSICURL];
|
||||
NSString *targetUrl = call.arguments[ARGUMENT_KEY_TARGETURL];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
QQApiAudioObject *object = nil;
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
NSString *title = call.arguments[ARGUMENT_KEY_TITLE];
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
NSString *musicUrl = call.arguments[ARGUMENT_KEY_MUSICURL];
|
||||
NSString *targetUrl = call.arguments[ARGUMENT_KEY_TARGETURL];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
QQApiAudioObject *object = nil;
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
}
|
||||
object.flashURL = [NSURL URLWithString:musicUrl];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
object.flashURL = [NSURL URLWithString:musicUrl];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
result(nil);
|
||||
result(nil);
|
||||
}
|
||||
|
||||
- (void)shareWebpage:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
NSString *title = call.arguments[ARGUMENT_KEY_TITLE];
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
NSString *targetUrl = call.arguments[ARGUMENT_KEY_TARGETURL];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
NSNumber *scene = call.arguments[ARGUMENT_KEY_SCENE];
|
||||
NSString *title = call.arguments[ARGUMENT_KEY_TITLE];
|
||||
NSString *summary = call.arguments[ARGUMENT_KEY_SUMMARY];
|
||||
NSString *imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
NSString *targetUrl = call.arguments[ARGUMENT_KEY_TARGETURL];
|
||||
// NSString *appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber *extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
|
||||
QQApiNewsObject *object = nil;
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
}
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
[QQApiInterface sendReq:req];
|
||||
} else if (scene.intValue == SCENE_QZONE) {
|
||||
[QQApiInterface SendReqToQZone:req];
|
||||
}
|
||||
result(nil);
|
||||
QQApiNewsObject *object = nil;
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
}
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
[QQApiInterface sendReq:req];
|
||||
} else if (scene.intValue == SCENE_QZONE) {
|
||||
[QQApiInterface SendReqToQZone:req];
|
||||
}
|
||||
result(nil);
|
||||
}
|
||||
|
||||
#pragma mark - AppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url
|
||||
delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
openURL:(NSURL *)url
|
||||
sourceApplication:(NSString *)sourceApplication
|
||||
annotation:(id)annotation {
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url
|
||||
delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
openURL:(NSURL *)url
|
||||
options:
|
||||
(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
return
|
||||
[QQApiInterface handleOpenURL:url
|
||||
delegate:self] ||
|
||||
([TencentOAuth CanHandleOpenURL:url] && [TencentOAuth HandleOpenURL:url]);
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
continueUserActivity:(NSUserActivity *)userActivity
|
||||
restorationHandler:(void (^)(NSArray *_Nonnull))restorationHandler {
|
||||
if ([userActivity.activityType
|
||||
isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||
NSURL *url = userActivity.webpageURL;
|
||||
if (url != nil) {
|
||||
return [QQApiInterface handleOpenUniversallink:url delegate:self] ||
|
||||
([TencentOAuth CanHandleUniversalLink:url] &&
|
||||
[TencentOAuth HandleUniversalLink:url]);
|
||||
if ([userActivity.activityType
|
||||
isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||
NSURL *url = userActivity.webpageURL;
|
||||
if (url != nil) {
|
||||
return [QQApiInterface handleOpenUniversallink:url delegate:self] ||
|
||||
([TencentOAuth CanHandleUniversalLink:url] &&
|
||||
[TencentOAuth HandleUniversalLink:url]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - TencentSessionDelegate
|
||||
|
||||
- (void)tencentDidLogin {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {
|
||||
NSString *openId = _oauth.openId;
|
||||
NSString *accessToken = _oauth.accessToken;
|
||||
long long expiresIn =
|
||||
ceil(_oauth.expirationDate.timeIntervalSinceNow); // 向上取整
|
||||
long long createAt = [[NSDate date] timeIntervalSince1970] * 1000.0;
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_SUCCESS]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[dictionary setValue:openId forKey:ARGUMENT_KEY_RESULT_OPENID];
|
||||
[dictionary setValue:accessToken forKey:ARGUMENT_KEY_RESULT_ACCESS_TOKEN];
|
||||
[dictionary setValue:[NSNumber numberWithLongLong:expiresIn]
|
||||
forKey:ARGUMENT_KEY_RESULT_EXPIRES_IN];
|
||||
[dictionary setValue:[NSNumber numberWithLongLong:createAt]
|
||||
forKey:ARGUMENT_KEY_RESULT_CREATE_AT];
|
||||
} else {
|
||||
// 登录失败
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {
|
||||
NSString *openId = _oauth.openId;
|
||||
NSString *accessToken = _oauth.accessToken;
|
||||
long long expiresIn =
|
||||
ceil(_oauth.expirationDate.timeIntervalSinceNow); // 向上取整
|
||||
long long createAt = [[NSDate date] timeIntervalSince1970] * 1000.0;
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_SUCCESS]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[dictionary setValue:openId forKey:ARGUMENT_KEY_RESULT_OPENID];
|
||||
[dictionary setValue:accessToken forKey:ARGUMENT_KEY_RESULT_ACCESS_TOKEN];
|
||||
[dictionary setValue:[NSNumber numberWithLongLong:expiresIn]
|
||||
forKey:ARGUMENT_KEY_RESULT_EXPIRES_IN];
|
||||
[dictionary setValue:[NSNumber numberWithLongLong:createAt]
|
||||
forKey:ARGUMENT_KEY_RESULT_CREATE_AT];
|
||||
} else {
|
||||
// 登录失败
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
|
||||
- (void)tencentDidNotLogin:(BOOL)cancelled {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if (cancelled) {
|
||||
// 取消登录
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
} else {
|
||||
// 登录失败
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if (cancelled) {
|
||||
// 取消登录
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
} else {
|
||||
// 登录失败
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
|
||||
- (void)tencentDidNotNetWork {
|
||||
// 登录失败
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
// 登录失败
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
|
||||
#pragma mark - QQApiInterfaceDelegate
|
||||
@ -338,30 +341,30 @@ static NSString *const SCHEME_FILE = @"file";
|
||||
}
|
||||
|
||||
- (void)onResp:(QQBaseResp *)resp {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if ([resp isKindOfClass:[SendMessageToQQResp class]]) {
|
||||
switch (resp.result.intValue) {
|
||||
case 0:
|
||||
// 分享成功
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_SUCCESS]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
break;
|
||||
case -4:
|
||||
// 用户取消
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
break;
|
||||
default:
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
NSString *errorMsg =
|
||||
[NSString stringWithFormat:@"result: %@, description: %@.",
|
||||
resp.result, resp.errorDescription];
|
||||
[dictionary setValue:errorMsg forKey:ARGUMENT_KEY_RESULT_MSG];
|
||||
break;
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if ([resp isKindOfClass:[SendMessageToQQResp class]]) {
|
||||
switch (resp.result.intValue) {
|
||||
case 0:
|
||||
// 分享成功
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_SUCCESS]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
break;
|
||||
case -4:
|
||||
// 用户取消
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
break;
|
||||
default:
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
NSString *errorMsg =
|
||||
[NSString stringWithFormat:@"result: %@, description: %@.",
|
||||
resp.result, resp.errorDescription];
|
||||
[dictionary setValue:errorMsg forKey:ARGUMENT_KEY_RESULT_MSG];
|
||||
break;
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONSHARERESP arguments:dictionary];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONSHARERESP arguments:dictionary];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)isOnlineResponse:(NSDictionary *)response {
|
||||
|
Reference in New Issue
Block a user