feat: 优化分享功能和剪贴板管理
- 修改gameController分享逻辑,支持不同分享类型 - 新增PasteboardManager类,优化iOS 14+剪贴板访问 - 减少剪贴板权限弹窗,提升用户体验
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#import "QiniuManager.h"
|
||||
#import "QiniuConfig.h"
|
||||
#import "SharePanel.h"
|
||||
#import "WechatShareManager.h"
|
||||
|
||||
@interface gameController ()
|
||||
<WKNavigationDelegate,WXApiManagerDelegate,VoiceRecorderBaseVCDelegate,AVAudioPlayerDelegate,ASIHTTPRequestDelegate,AMapLocationManagerDelegate,UIActionSheetDelegate,AgoraRtcEngineDelegate>
|
||||
@@ -581,11 +582,19 @@
|
||||
enum WXScene currentScene;
|
||||
int friend = [one intValue];
|
||||
// ======测试分享面板
|
||||
if(friend ==1){
|
||||
// 显示分享面板
|
||||
[SharePanel showWithDictionary:data completion:^(ShareType type, BOOL success) {
|
||||
// 处理分享结果
|
||||
}];
|
||||
|
||||
// 显示分享面板
|
||||
[SharePanel showWithDictionary:data completion:^(ShareType type, BOOL success) {
|
||||
// 处理分享结果
|
||||
}];
|
||||
}else{
|
||||
// 使用WechatShareManager处理微信分享
|
||||
[WechatShareManager shareWithContent:data
|
||||
completion:^(BOOL success) {
|
||||
|
||||
}];
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
|
||||
42
msext/Class/Utils/PasteboardManager.h
Normal file
42
msext/Class/Utils/PasteboardManager.h
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// PasteboardManager.h
|
||||
// msext
|
||||
//
|
||||
// Created on 2025/06/17.
|
||||
// Copyright © 2025年. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* 剪贴板管理器 - 优化iOS 14+的剪贴板访问,减少权限弹窗
|
||||
*/
|
||||
@interface PasteboardManager : NSObject
|
||||
|
||||
/**
|
||||
* 安全地读取剪贴板文本内容
|
||||
* 在iOS 14+中会先检查是否有内容,避免不必要的权限弹窗
|
||||
*/
|
||||
+ (nullable NSString *)safeReadPasteboardText;
|
||||
|
||||
/**
|
||||
* 写入文本到剪贴板
|
||||
*/
|
||||
+ (void)writeTextToPasteboard:(NSString *)text;
|
||||
|
||||
/**
|
||||
* 检查剪贴板是否有文本内容(iOS 14+可用,不会触发权限弹窗)
|
||||
*/
|
||||
+ (BOOL)hasTextInPasteboard API_AVAILABLE(ios(14.0));
|
||||
|
||||
/**
|
||||
* 清空剪贴板内容
|
||||
*/
|
||||
+ (void)clearPasteboard;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
71
msext/Class/Utils/PasteboardManager.m
Normal file
71
msext/Class/Utils/PasteboardManager.m
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// PasteboardManager.m
|
||||
// msext
|
||||
//
|
||||
// Created on 2025/06/17.
|
||||
// Copyright © 2025年. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PasteboardManager.h"
|
||||
|
||||
@implementation PasteboardManager
|
||||
|
||||
#pragma mark - Public Methods
|
||||
|
||||
+ (nullable NSString *)safeReadPasteboardText {
|
||||
NSLog(@"🔍 [PasteboardManager] 尝试安全读取剪贴板内容");
|
||||
|
||||
if (@available(iOS 14.0, *)) {
|
||||
// iOS 14+ 先检查是否有文本内容,避免不必要的权限弹窗
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
|
||||
if (pasteboard.hasStrings) {
|
||||
NSString *text = pasteboard.string;
|
||||
NSLog(@"✅ [PasteboardManager] 成功读取剪贴板文本: %@", text ? @"有内容" : @"空内容");
|
||||
return text ?: @"";
|
||||
} else {
|
||||
NSLog(@"ℹ️ [PasteboardManager] 剪贴板中无文本内容");
|
||||
return @"";
|
||||
}
|
||||
} else {
|
||||
// iOS 14以下直接读取
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
NSString *text = pasteboard.string;
|
||||
NSLog(@"✅ [PasteboardManager] 读取剪贴板文本: %@", text ? @"有内容" : @"空内容");
|
||||
return text ?: @"";
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)writeTextToPasteboard:(NSString *)text {
|
||||
NSLog(@"🔍 [PasteboardManager] 写入文本到剪贴板: %@", text ? @"有内容" : @"空内容");
|
||||
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
pasteboard.string = text ?: @"";
|
||||
|
||||
NSLog(@"✅ [PasteboardManager] 文本已写入剪贴板");
|
||||
}
|
||||
|
||||
+ (BOOL)hasTextInPasteboard {
|
||||
if (@available(iOS 14.0, *)) {
|
||||
BOOL hasText = [UIPasteboard generalPasteboard].hasStrings;
|
||||
NSLog(@"🔍 [PasteboardManager] 检查剪贴板是否有文本: %@", hasText ? @"是" : @"否");
|
||||
return hasText;
|
||||
} else {
|
||||
// iOS 14以下版本需要直接访问内容来判断
|
||||
NSString *text = [UIPasteboard generalPasteboard].string;
|
||||
BOOL hasText = (text != nil && text.length > 0);
|
||||
NSLog(@"🔍 [PasteboardManager] 检查剪贴板是否有文本: %@", hasText ? @"是" : @"否");
|
||||
return hasText;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)clearPasteboard {
|
||||
NSLog(@"🔍 [PasteboardManager] 清空剪贴板");
|
||||
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
pasteboard.string = @"";
|
||||
|
||||
NSLog(@"✅ [PasteboardManager] 剪贴板已清空");
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user