2023-10-16 17:18:10 +08:00
|
|
|
#import "XSFlutterManager.h"
|
2023-10-14 17:08:25 +08:00
|
|
|
#include "GeneratedPluginRegistrant.h"
|
|
|
|
|
#import "CommonDefine.h"
|
|
|
|
|
|
2023-10-16 17:18:10 +08:00
|
|
|
@interface XSFlutterManager ()
|
2023-10-14 17:08:25 +08:00
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
@property(nonatomic, strong) FlutterMethodChannel *methodChannel;
|
|
|
|
|
@property(nonatomic, copy) NSString *textToShare;
|
|
|
|
|
@property(nonatomic, copy) NSString *urlToShare;
|
|
|
|
|
@property(nonatomic, copy) NSArray *activityItems;
|
2023-10-14 17:08:25 +08:00
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
@implementation XSFlutterManager
|
2023-10-14 17:08:25 +08:00
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
self.textToShare = [[NSString alloc] init];
|
2024-06-21 10:41:11 +08:00
|
|
|
self.urlToShare = [[NSString alloc] init];
|
|
|
|
|
self.activityItems = [[NSArray alloc] init];
|
2024-06-04 15:48:39 +08:00
|
|
|
|
2023-10-14 17:08:25 +08:00
|
|
|
[self methodChannelFunction];
|
|
|
|
|
}
|
2024-06-21 10:41:11 +08:00
|
|
|
|
2023-10-14 17:08:25 +08:00
|
|
|
- (void)methodChannelFunction {
|
2024-06-21 10:41:11 +08:00
|
|
|
// 创建 FlutterMethodChannel
|
|
|
|
|
self.methodChannel = [FlutterMethodChannel methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
|
2023-10-14 17:08:25 +08:00
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
// 设置监听
|
|
|
|
|
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall *methodCall, FlutterResult result) {
|
|
|
|
|
NSString *method = methodCall.method;
|
|
|
|
|
// 调用系统分享
|
2023-11-01 14:18:52 +08:00
|
|
|
if ([method isEqualToString:XSflutterMethodSharePassword]) {
|
|
|
|
|
id params = methodCall.arguments;
|
2023-10-14 17:08:25 +08:00
|
|
|
self.textToShare = @"您好,您的密码是:";
|
2023-11-01 14:18:52 +08:00
|
|
|
if ([params isKindOfClass:[NSDictionary class]]) {
|
|
|
|
|
NSDictionary *paramDic = (NSDictionary *)params;
|
2024-06-21 10:41:11 +08:00
|
|
|
// 分享的标题
|
2024-01-24 18:44:34 +08:00
|
|
|
self.textToShare = paramDic[@"shareText"];
|
2024-06-04 15:48:39 +08:00
|
|
|
self.urlToShare = paramDic[@"urlToShare"];
|
2023-11-01 14:18:52 +08:00
|
|
|
}
|
2024-06-21 10:41:11 +08:00
|
|
|
|
|
|
|
|
if ([self.urlToShare isEqualToString:@"fileShare"]) {
|
2024-06-21 09:28:25 +08:00
|
|
|
// 创建要分享或操作的文件对象
|
2024-06-21 10:41:11 +08:00
|
|
|
NSURL *fileURL = [NSURL fileURLWithPath:self.textToShare];
|
2024-06-04 15:48:39 +08:00
|
|
|
|
2024-06-21 09:28:25 +08:00
|
|
|
// 将文件对象添加到数组中
|
2024-06-21 10:41:11 +08:00
|
|
|
self.activityItems = @[fileURL];
|
2024-06-21 09:28:25 +08:00
|
|
|
} else {
|
2024-06-21 10:41:11 +08:00
|
|
|
// 分享的 URL
|
2024-06-21 09:28:25 +08:00
|
|
|
NSURL *urlToShare = [NSURL URLWithString:self.urlToShare];
|
|
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
// 在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
|
|
|
|
|
self.activityItems = @[self.textToShare, urlToShare];
|
2024-06-21 09:28:25 +08:00
|
|
|
}
|
2023-11-01 14:18:52 +08:00
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:self.activityItems applicationActivities:nil];
|
2023-11-01 14:18:52 +08:00
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
// 不出现在活动项目
|
2023-11-01 14:18:52 +08:00
|
|
|
activityVC.excludedActivityTypes = @[UIActivityTypePrint];
|
2024-01-30 10:18:39 +08:00
|
|
|
[self presentViewController:activityVC animated:YES completion:nil];
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
|
|
|
// 分享之后的回调
|
|
|
|
|
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
2023-10-14 17:08:25 +08:00
|
|
|
if (completed) {
|
|
|
|
|
NSLog(@"completed");
|
2025-02-13 10:56:24 +08:00
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
// 分享成功
|
|
|
|
|
} else {
|
|
|
|
|
NSLog(@"canceled");
|
|
|
|
|
// 分享取消
|
2023-10-14 17:08:25 +08:00
|
|
|
}
|
2023-11-01 14:18:52 +08:00
|
|
|
};
|
2023-10-14 17:08:25 +08:00
|
|
|
result(@"push返回到flutter");
|
|
|
|
|
}
|
2025-02-13 10:56:24 +08:00
|
|
|
if ([method isEqualToString:@"getBundleIdentifier"]) {
|
|
|
|
|
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
|
|
|
|
|
result(bundleIdentifier); // 返回 Bundle Identifier
|
|
|
|
|
}
|
2023-10-14 17:08:25 +08:00
|
|
|
}];
|
2024-06-21 10:41:11 +08:00
|
|
|
|
2023-10-14 17:08:25 +08:00
|
|
|
[GeneratedPluginRegistrant registerWithRegistry:self];
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2023-10-14 17:08:25 +08:00
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
[self.navigationController setNavigationBarHidden:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-21 10:41:11 +08:00
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
2023-10-14 17:08:25 +08:00
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
[self.navigationController setNavigationBarHidden:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2024-06-21 10:41:11 +08:00
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
|
}
|
|
|
|
|
*/
|
2023-10-14 17:08:25 +08:00
|
|
|
|
|
|
|
|
@end
|