app-starlock/ios/Runner/XSFlutterManager.m

106 lines
3.9 KiB
Mathematica
Raw Permalink Normal View History

#import "XSFlutterManager.h"
2023-10-14 17:08:25 +08:00
#include "GeneratedPluginRegistrant.h"
#import "CommonDefine.h"
@interface XSFlutterManager ()
2023-10-14 17:08:25 +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
@implementation XSFlutterManager
2023-10-14 17:08:25 +08:00
- (void)viewDidLoad {
[super viewDidLoad];
self.textToShare = [[NSString alloc] init];
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];
}
2023-10-14 17:08:25 +08:00
- (void)methodChannelFunction {
// FlutterMethodChannel
self.methodChannel = [FlutterMethodChannel methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
2023-10-14 17:08:25 +08:00
//
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall *methodCall, FlutterResult result) {
NSString *method = methodCall.method;
//
if ([method isEqualToString:XSflutterMethodSharePassword]) {
id params = methodCall.arguments;
2023-10-14 17:08:25 +08:00
self.textToShare = @"您好,您的密码是:";
if ([params isKindOfClass:[NSDictionary class]]) {
NSDictionary *paramDic = (NSDictionary *)params;
//
self.textToShare = paramDic[@"shareText"];
2024-06-04 15:48:39 +08:00
self.urlToShare = paramDic[@"urlToShare"];
}
if ([self.urlToShare isEqualToString:@"fileShare"]) {
2024-06-21 09:28:25 +08:00
//
NSURL *fileURL = [NSURL fileURLWithPath:self.textToShare];
2024-06-04 15:48:39 +08:00
2024-06-21 09:28:25 +08:00
//
self.activityItems = @[fileURL];
2024-06-21 09:28:25 +08:00
} else {
// URL
2024-06-21 09:28:25 +08:00
NSURL *urlToShare = [NSURL URLWithString:self.urlToShare];
//
self.activityItems = @[self.textToShare, urlToShare];
2024-06-21 09:28:25 +08:00
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:self.activityItems applicationActivities:nil];
//
activityVC.excludedActivityTypes = @[UIActivityTypePrint];
2024-01-30 10:18:39 +08:00
[self presentViewController:activityVC animated:YES completion:nil];
//
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
//
} else {
NSLog(@"canceled");
//
2023-10-14 17:08:25 +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
}];
2023-10-14 17:08:25 +08:00
[GeneratedPluginRegistrant registerWithRegistry:self];
}
- (void)viewWillAppear:(BOOL)animated {
2023-10-14 17:08:25 +08:00
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
2023-10-14 17:08:25 +08:00
[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.
}
*/
2023-10-14 17:08:25 +08:00
@end