From 2543e7b610120582991632d555cce5bfc74abdac Mon Sep 17 00:00:00 2001 From: wrapping-2000 Date: Tue, 1 Aug 2023 20:46:43 +0800 Subject: [PATCH] fix: fix variable' format and comment the native code of WeChat. --- ios/Classes/OcCasdoorFlutterSdkPlugin.m | 108 ++++++++++++------------ lib/casdoor_flutter_sdk_oauth.dart | 6 +- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/ios/Classes/OcCasdoorFlutterSdkPlugin.m b/ios/Classes/OcCasdoorFlutterSdkPlugin.m index 906997f..7caeb89 100644 --- a/ios/Classes/OcCasdoorFlutterSdkPlugin.m +++ b/ios/Classes/OcCasdoorFlutterSdkPlugin.m @@ -15,13 +15,13 @@ #import #import "CasdoorFlutterSdkPlugin.h" #import -#import -#import -#import +// #import +// #import +// #import @import WebKit; -#define APP_ID @"wx049c70e6c2027b0b" -#define UNIVERSAL_LINK @"https://testdomain.com" +// #define APP_ID @"wx049c70e6c2027b0b" +// #define UNIVERSAL_LINK @"https://testdomain.com" typedef void (^AuthResultCallback)(NSString *); @@ -88,59 +88,59 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { NSString *app_id = arguments[@"app_id"]; NSString *universal_link = arguments[@"universal_link"]; // register WeChat - BOOL isWeChatRegistered = [WXApi registerApp:app_id universalLink:universal_link]; - NSLog(@"Is WeChat Registered: %@", isWeChatRegistered ? @"YES" : @"NO"); +// BOOL isWeChatRegistered = [WXApi registerApp:app_id universalLink:universal_link]; +// NSLog(@"Is WeChat Registered: %@", isWeChatRegistered ? @"YES" : @"NO"); }else { result(FlutterMethodNotImplemented); } } -- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { - return [WXApi handleOpenURL:url delegate:self]; -} - -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - return [WXApi handleOpenURL:url delegate:self]; -} +// - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { +// return [WXApi handleOpenURL:url delegate:self]; +// } -- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray> * __nullable restorableObjects))restorationHandler { - return [WXApi handleOpenUniversalLink:userActivity delegate:self]; -} +// - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { +// return [WXApi handleOpenURL:url delegate:self]; +// } --(void) onReq:(BaseReq*)reqonReq { +// - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray> * __nullable restorableObjects))restorationHandler { +// return [WXApi handleOpenUniversalLink:userActivity delegate:self]; +// } -} - --(void) onResp:(BaseResp*)resp { - /* - enum WXErrCode { - WXSuccess = 0, 成功 - WXErrCodeCommon = -1, 普通错误类型 - WXErrCodeUserCancel = -2, 用户点击取消并返回 - WXErrCodeSentFail = -3, 发送失败 - WXErrCodeAuthDeny = -4, 授权失败 - WXErrCodeUnsupport = -5, 微信不支持 - }; - */ - if (resp.errCode == 0) { //Success - NSLog(@"Login Success."); - SendAuthResp *resp2 = (SendAuthResp *)resp; - NSLog(@"code: %@", resp2.code); - - }else{ //Failed - NSLog(@"error %@", resp.errStr); - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Login failed." message:[NSString stringWithFormat:@"reason: %@", resp.errStr] preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancle" style:UIAlertActionStyleCancel handler:nil]; - UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:nil]; - - [alertController addAction:cancelAction]; - [alertController addAction:confirmAction]; - - UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController; - [rootViewController presentViewController:alertController animated:YES completion:nil]; - } -} +// -(void) onReq:(BaseReq*)reqonReq { +// +// } + +// -(void) onResp:(BaseResp*)resp { +// /* +// enum WXErrCode { +// WXSuccess = 0, 成功 +// WXErrCodeCommon = -1, 普通错误类型 +// WXErrCodeUserCancel = -2, 用户点击取消并返回 +// WXErrCodeSentFail = -3, 发送失败 +// WXErrCodeAuthDeny = -4, 授权失败 +// WXErrCodeUnsupport = -5, 微信不支持 +// }; +// */ +// if (resp.errCode == 0) { //Success +// NSLog(@"Login Success."); +// SendAuthResp *resp2 = (SendAuthResp *)resp; +// NSLog(@"code: %@", resp2.code); +// +// }else{ //Failed +// NSLog(@"error %@", resp.errStr); +// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Login failed." message:[NSString stringWithFormat:@"reason: %@", resp.errStr] preferredStyle:UIAlertControllerStyleAlert]; +// +// UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancle" style:UIAlertActionStyleCancel handler:nil]; +// UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:nil]; +// +// [alertController addAction:cancelAction]; +// [alertController addAction:confirmAction]; +// +// UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController; +// [rootViewController presentViewController:alertController animated:YES completion:nil]; +// } +// } #pragma mark - WKNavigationDelegate @@ -172,10 +172,10 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati // NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion); // }]; - SendAuthReq *req = [[SendAuthReq alloc]init]; - req.scope = @"snsapi_userinfo"; - req.state = @"wx_oauth_authorization_state"; - [WXApi sendReq:req completion:nil]; +// SendAuthReq *req = [[SendAuthReq alloc]init]; +// req.scope = @"snsapi_userinfo"; +// req.state = @"wx_oauth_authorization_state"; +// [WXApi sendReq:req completion:nil]; decisionHandler(WKNavigationActionPolicyCancel); diff --git a/lib/casdoor_flutter_sdk_oauth.dart b/lib/casdoor_flutter_sdk_oauth.dart index 6c1221e..02542cb 100644 --- a/lib/casdoor_flutter_sdk_oauth.dart +++ b/lib/casdoor_flutter_sdk_oauth.dart @@ -38,10 +38,10 @@ class CasdoorOauth { return CasdoorFlutterSdkPlatform.instance.getPlatformVersion(); } - static Future registerWXApi({required String app_id, required String universal_link}) async { + static Future registerWXApi({required String appId, required String universalLink}) async { return await _channel.invokeMethod('registerWXApi', { - 'app_id': app_id, - 'universal_link': universal_link, + 'app_id': appId, + 'universal_link': universalLink, }) as String; }