feat: 重构分享功能 - 将各平台分享逻辑整理到对应Manager中

- 新增 WechatShareManager:封装微信分享逻辑,支持ShareContent对象
- 增强 DouyinShareManager:新增ShareContent支持和分享引导功能
- 优化 QQShareManager:支持截图/纯文本分享类型自动识别
- 重构 SharePanel:简化为UI调度层,移除具体分享实现
- 实现职责分离:各Manager专注自己的平台分享逻辑
- 提升可维护性:修改某平台不影响其他平台
- 增强可扩展性:新增分享平台更容易实现
This commit is contained in:
joywayer
2025-06-17 19:55:44 +08:00
parent 1666d6cf24
commit 2296c65974
13 changed files with 3730 additions and 2 deletions

View File

@@ -0,0 +1,222 @@
//
// QQAppIDValidator.m
// msext
//
// Created on 2025/06/16.
// Copyright © 2025. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "QQShareManager.h"
/**
* QQ AppID
* SDKQQ
*/
@interface QQAppIDValidator : NSObject
/**
* QQ
* AppIDURL Schemes
*/
+ (void)performCompleteValidation;
/**
*
*/
+ (void)showValidationResults;
/**
* QQURL
*/
+ (NSString *)generateTestQQShareURL;
@end
@implementation QQAppIDValidator
+ (void)performCompleteValidation {
NSLog(@"\n🔍 开始QQ分享配置验证...\n");
// 1. QQ
BOOL isQQInstalled = [QQShareManager isQQInstalled];
NSLog(@"1⃣ QQ安装检查: %@", isQQInstalled ? @"✅ 已安装" : @"❌ 未安装");
// 2. AppID
BOOL isAppIDValid = [QQShareManager validateQQAppIDConfiguration];
NSString *appID = [QQShareManager getCurrentQQAppID];
NSLog(@"2⃣ AppID配置检查: %@", isAppIDValid ? [NSString stringWithFormat:@"✅ 有效 (%@)", appID] : @"❌ 无效");
// 3. URL Schemes
[self validateURLSchemes];
// 4.
[self validateCallbackConfiguration];
// 5. URL
NSString *testURL = [self generateTestQQShareURL];
NSLog(@"5⃣ 测试分享URL: %@", testURL);
NSLog(@"\n✅ QQ分享配置验证完成\n");
}
+ (void)validateURLSchemes {
NSArray *requiredSchemes = @[@"mqqapi", @"mqq", @"mqqOpensdkSSoLogin", @"mqqopensdkapiV2", @"mqqopensdkapiV3", @"mqqopensdkapiV4", @"wtloginmqq2", @"mqzone"];
BOOL allSchemesConfigured = YES;
NSMutableArray *missingSchemes = [NSMutableArray array];
for (NSString *scheme in requiredSchemes) {
NSString *testURLString = [NSString stringWithFormat:@"%@://test", scheme];
NSURL *testURL = [NSURL URLWithString:testURLString];
if (![[UIApplication sharedApplication] canOpenURL:testURL]) {
allSchemesConfigured = NO;
[missingSchemes addObject:scheme];
}
}
if (allSchemesConfigured) {
NSLog(@"3⃣ URL Schemes配置: ✅ 完整");
} else {
NSLog(@"3⃣ URL Schemes配置: ❌ 缺少 %@", [missingSchemes componentsJoinedByString:@", "]);
NSLog(@" 请在Info.plist的LSApplicationQueriesSchemes中添加缺少的schemes");
}
}
+ (void)validateCallbackConfiguration {
// msextscheme
NSURL *callbackURL = [NSURL URLWithString:@"msext://test"];
NSBundle *mainBundle = [NSBundle mainBundle];
NSDictionary *infoPlist = [mainBundle infoDictionary];
NSArray *urlTypes = infoPlist[@"CFBundleURLTypes"];
BOOL callbackConfigured = NO;
for (NSDictionary *urlType in urlTypes) {
NSArray *schemes = urlType[@"CFBundleURLSchemes"];
if ([schemes containsObject:@"msext"]) {
callbackConfigured = YES;
break;
}
}
NSLog(@"4⃣ 回调配置检查: %@", callbackConfigured ? @"✅ 正确" : @"❌ 缺失msext scheme");
if (!callbackConfigured) {
NSLog(@" 请在Info.plist的CFBundleURLTypes中添加msext scheme配置");
}
}
+ (NSString *)generateTestQQShareURL {
NSString *appID = [QQShareManager getCurrentQQAppID];
if (!appID) {
return @"❌ 无法生成测试URLAppID未配置";
}
// QQURL
NSMutableString *testURL = [NSMutableString stringWithString:@"mqqapi://share/to_fri?"];
[testURL appendString:@"version=1"];
[testURL appendString:@"&cflag=0"];
[testURL appendString:@"&src_type=app"];
[testURL appendString:@"&sdkv=2.9.0"];
[testURL appendString:@"&sdkp=i"];
[testURL appendFormat:@"&appid=%@", appID];
[testURL appendString:@"&app_name=进贤聚友棋牌"];
[testURL appendString:@"&callback_type=scheme"];
[testURL appendString:@"&callback_name=msext"];
[testURL appendString:@"&req_type=0"];
[testURL appendString:@"&title=测试标题"];
[testURL appendString:@"&description=测试描述"];
return testURL;
}
+ (void)showValidationResults {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"QQ分享配置验证"
message:@"请查看控制台日志以获取详细的验证结果"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *validateAction = [UIAlertAction actionWithTitle:@"重新验证"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self performCompleteValidation];
}];
UIAlertAction *testAction = [UIAlertAction actionWithTitle:@"测试分享"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self performTestShare];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"关闭"
style:UIAlertActionStyleCancel
handler:nil];
[alert addAction:validateAction];
[alert addAction:testAction];
[alert addAction:cancelAction];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = [self topViewController:rootVC];
[topVC presentViewController:alert animated:YES completion:nil];
});
}
+ (void)performTestShare {
NSLog(@"🧪 开始QQ分享测试...");
[QQShareManager shareToQQFriend:QQShareTypeText
title:@"QQ分享配置测试"
description:@"如果您看到这条消息说明QQ分享配置正确"
thumbImage:nil
url:nil
image:nil
completion:^(BOOL success) {
NSLog(@"🧪 QQ分享测试结果: %@", success ? @"✅ 成功" : @"❌ 失败");
dispatch_async(dispatch_get_main_queue(), ^{
NSString *message = success ? @"QQ分享测试成功配置正确。" : @"QQ分享测试失败请检查配置。";
UIAlertController *resultAlert = [UIAlertController alertControllerWithTitle:@"测试结果"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[resultAlert addAction:okAction];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = [self topViewController:rootVC];
[topVC presentViewController:resultAlert animated:YES completion:nil];
});
}];
}
+ (UIViewController *)topViewController:(UIViewController *)rootViewController {
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
if ([rootViewController.presentedViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController.presentedViewController;
UIViewController *selectedViewController = tabBarController.selectedViewController;
return [self topViewController:selectedViewController];
}
return [self topViewController:rootViewController.presentedViewController];
}
@end
// 便
void validateQQShareConfiguration(void) {
[QQAppIDValidator performCompleteValidation];
}
void showQQShareValidationDialog(void) {
[QQAppIDValidator showValidationResults];
}