// // 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{ SystemSoundID okSound; SystemSoundID noticeSound; SystemSoundID errorSound; SystemSoundID alarmSound; SystemSoundID ringSound; } @synthesize sysinfo; //@synthesize db; - (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]; [[Pub getApp].window.rootViewController 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"); } else if ([method isEqualToString:XSflutterMethodVideoTalk]) { id params = methodCall.arguments; if ([params isKindOfClass:[NSDictionary class]]) { NSDictionary *paramDic = (NSDictionary *)params; NSLog(@"得到了参数%@", paramDic[@"videoTalk"]); } sysinfo = [[sysInfo alloc] init]; [sysinfo initDB]; [sysinfo readSystemInfo]; // BaseViewController * VC = [[BaseViewController alloc]init]; // [Pub getApp].window.rootViewController = VC; // [[Pub getApp].window makeKeyAndVisible]; [self initSound]; _udp = [[UdpHelper alloc] init]; [_udp Open]; _talk = [[talk_Class alloc] init]; sysinfo.launchtime = [Sformat timestamp]; } }]; [GeneratedPluginRegistrant registerWithRegistry:self]; } - (void)initSound { CFURLRef okURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ok" ofType:@"wav"]]); CFURLRef noticeURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]); CFURLRef errURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"err" ofType:@"wav"]]); CFURLRef alarmURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"]]); CFURLRef ringURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]); AudioServicesCreateSystemSoundID(okURL, &okSound); AudioServicesCreateSystemSoundID(noticeURL, ¬iceSound); AudioServicesCreateSystemSoundID(errURL, &errorSound); AudioServicesCreateSystemSoundID(alarmURL, &alarmSound); AudioServicesCreateSystemSoundID(ringURL, &ringSound); AudioServicesPropertyID flag = 0; //0 means always play AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &okSound, sizeof(AudioServicesPropertyID), &flag); AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), ¬iceSound, sizeof(AudioServicesPropertyID), &flag); AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &errorSound, sizeof(AudioServicesPropertyID), &flag); AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &alarmSound, sizeof(AudioServicesPropertyID), &flag); AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &ringSound, sizeof(AudioServicesPropertyID), &flag); CFBridgingRelease(okURL); CFBridgingRelease(noticeURL); CFBridgingRelease(errURL); CFBridgingRelease(alarmURL); CFBridgingRelease(ringURL); } -(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