#import "XSFlutterManager.h" #include "GeneratedPluginRegistrant.h" #import "CommonDefine.h" @interface XSFlutterManager () @property(nonatomic, strong) FlutterMethodChannel *methodChannel; @property(nonatomic, copy) NSString *textToShare; @property(nonatomic, copy) NSString *urlToShare; @property(nonatomic, copy) NSArray *activityItems; @end @implementation XSFlutterManager - (void)viewDidLoad { [super viewDidLoad]; self.textToShare = [[NSString alloc] init]; self.urlToShare = [[NSString alloc] init]; self.activityItems = [[NSArray alloc] init]; [self methodChannelFunction]; } - (void)methodChannelFunction { // 创建 FlutterMethodChannel self.methodChannel = [FlutterMethodChannel methodChannelWithName:XSflutterMethodChannel binaryMessenger:self]; // 设置监听 [self.methodChannel setMethodCallHandler:^(FlutterMethodCall *methodCall, FlutterResult result) { NSString *method = methodCall.method; // 调用系统分享 if ([method isEqualToString:XSflutterMethodSharePassword]) { id params = methodCall.arguments; self.textToShare = @"您好,您的密码是:"; if ([params isKindOfClass:[NSDictionary class]]) { NSDictionary *paramDic = (NSDictionary *)params; // 分享的标题 self.textToShare = paramDic[@"shareText"]; self.urlToShare = paramDic[@"urlToShare"]; } if ([self.urlToShare isEqualToString:@"fileShare"]) { // 创建要分享或操作的文件对象 NSURL *fileURL = [NSURL fileURLWithPath:self.textToShare]; // 将文件对象添加到数组中 self.activityItems = @[fileURL]; } else { // 分享的 URL NSURL *urlToShare = [NSURL URLWithString:self.urlToShare]; // 在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上 self.activityItems = @[self.textToShare, urlToShare]; } UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:self.activityItems applicationActivities:nil]; // 不出现在活动项目 activityVC.excludedActivityTypes = @[UIActivityTypePrint]; [self presentViewController:activityVC animated:YES completion:nil]; // 分享之后的回调 activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) { if (completed) { NSLog(@"completed"); // 分享成功 } else { NSLog(@"canceled"); // 分享取消 } }; result(@"push返回到flutter"); } if ([method isEqualToString:@"getBundleIdentifier"]) { NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; result(bundleIdentifier); // 返回 Bundle Identifier } }]; [GeneratedPluginRegistrant registerWithRegistry:self]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO]; } /* #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. } */ @end