app-starlock/star_lock/ios/Runner/XSFlutterManager.m
2024-01-30 10:18:39 +08:00

101 lines
3.2 KiB
Objective-C

//
// XSFlutterManager.m
// Runner
//
// Created by DaisyWu on 2023/10/14.
//
#import "XSFlutterManager.h"
#include "GeneratedPluginRegistrant.h"
#import "CommonDefine.h"
@interface XSFlutterManager ()
@property(nonatomic,strong) FlutterMethodChannel* methodChannel;
@property (nonatomic, copy) NSString *textToShare;
@end
@implementation XSFlutterManager{
}
- (void)viewDidLoad {
[super viewDidLoad];
self.textToShare = [[NSString alloc] init];
[self methodChannelFunction];
}
- (void)methodChannelFunction {
//创建 FlutterMethodChannel
self.methodChannel = [FlutterMethodChannel
methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
//设置监听
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall* methodCall, FlutterResult result) {
// TODO
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"];
}
//分享的url
NSURL *urlToShare = [NSURL URLWithString:@"https://pre.lock.star-lock.cn:8093/login"];
//在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
NSArray *activityItems = @[self.textToShare,urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems: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(@"cancled");
//分享 取消
}
};
result(@"push返回到flutter");
}
}];
[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