mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-06-21 11:08:51 +08:00
OC代码格式化
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
#import "TencentKitPlugin.h"
|
||||
#import <TencentOpenAPI/TencentOAuth.h>
|
||||
#import <TencentOpenAPI/QQApiInterface.h>
|
||||
#import <TencentOpenAPI/TencentOAuth.h>
|
||||
|
||||
enum TencentScene {
|
||||
SCENE_QQ = 0,
|
||||
@ -27,10 +27,11 @@ enum TencentRetCode {
|
||||
}
|
||||
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
|
||||
FlutterMethodChannel* channel = [FlutterMethodChannel
|
||||
methodChannelWithName:@"v7lin.github.io/tencent_kit"
|
||||
FlutterMethodChannel *channel =
|
||||
[FlutterMethodChannel methodChannelWithName:@"v7lin.github.io/tencent_kit"
|
||||
binaryMessenger:[registrar messenger]];
|
||||
TencentKitPlugin* instance = [[TencentKitPlugin alloc] initWithChannel:channel];
|
||||
TencentKitPlugin *instance =
|
||||
[[TencentKitPlugin alloc] initWithChannel:channel];
|
||||
[registrar addApplicationDelegate:instance];
|
||||
[registrar addMethodCallDelegate:instance channel:channel];
|
||||
}
|
||||
@ -78,12 +79,15 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
- (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];
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId
|
||||
andUniversalLink:universalLink
|
||||
andDelegate:self];
|
||||
} else {
|
||||
_oauth = [[TencentOAuth alloc] initWithAppId:appId andDelegate:self];
|
||||
}
|
||||
@ -108,14 +112,18 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
}
|
||||
|
||||
- (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);
|
||||
}
|
||||
|
||||
- (void)logout:(FlutterMethodCall *)call result:(FlutterResult)result {
|
||||
if (_oauth != nil) {
|
||||
[_oauth logout:self];
|
||||
}
|
||||
result(nil);
|
||||
}
|
||||
|
||||
@ -135,11 +143,17 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
[imageDatas addObject:imageData];
|
||||
}
|
||||
}
|
||||
QQApiImageArrayForQZoneObject* object = [QQApiImageArrayForQZoneObject objectWithimageDataArray:imageDatas title:summary extMap:nil];
|
||||
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];
|
||||
QQApiVideoForQZoneObject *object =
|
||||
[QQApiVideoForQZoneObject objectWithAssetURL:videoUri
|
||||
title:summary
|
||||
extMap:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
@ -156,7 +170,10 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
|
||||
NSURL *imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
QQApiImageObject* object = [QQApiImageObject objectWithData:imageData previewImageData:nil title:nil description:nil];
|
||||
QQApiImageObject *object = [QQApiImageObject objectWithData:imageData
|
||||
previewImageData:nil
|
||||
title:nil
|
||||
description:nil];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
@ -177,9 +194,15 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
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];
|
||||
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 = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
}
|
||||
object.flashURL = [NSURL URLWithString:musicUrl];
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
@ -201,9 +224,15 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
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];
|
||||
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];
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl]
|
||||
title:title
|
||||
description:summary
|
||||
previewImageURL:imageUrl];
|
||||
}
|
||||
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:object];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
@ -217,22 +246,39 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
#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]);
|
||||
- (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]);
|
||||
}
|
||||
|
||||
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
||||
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]);
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nonnull))restorationHandler {
|
||||
if([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||
- (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]);
|
||||
return [QQApiInterface handleOpenUniversallink:url delegate:self] ||
|
||||
([TencentOAuth CanHandleUniversalLink:url] &&
|
||||
[TencentOAuth HandleUniversalLink:url]);
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
@ -245,16 +291,21 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
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 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:[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];
|
||||
[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];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
@ -263,10 +314,12 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
if (cancelled) {
|
||||
// 取消登录
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL] forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_USERCANCEL]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
} else {
|
||||
// 登录失败
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON] forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
}
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
@ -274,14 +327,14 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
- (void)tencentDidNotNetWork {
|
||||
// 登录失败
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON] forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_COMMON]
|
||||
forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[_channel invokeMethod:METHOD_ONLOGINRESP arguments:dictionary];
|
||||
}
|
||||
|
||||
#pragma mark - QQApiInterfaceDelegate
|
||||
|
||||
- (void)onReq:(QQBaseReq *)req {
|
||||
|
||||
}
|
||||
|
||||
- (void)onResp:(QQBaseResp *)resp {
|
||||
@ -290,15 +343,20 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
switch (resp.result.intValue) {
|
||||
case 0:
|
||||
// 分享成功
|
||||
[dictionary setValue:[NSNumber numberWithInt:RET_SUCCESS] forKey:ARGUMENT_KEY_RESULT_RET];
|
||||
[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];
|
||||
[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:[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;
|
||||
}
|
||||
@ -307,7 +365,6 @@ static NSString* const SCHEME_FILE = @"file";
|
||||
}
|
||||
|
||||
- (void)isOnlineResponse:(NSDictionary *)response {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user