新增iOS原生分享
This commit is contained in:
parent
83035edc44
commit
a4a92b79fd
@ -10,6 +10,7 @@
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
|
||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||
3EF1E85D6F1EE0C0DCF8449F /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09D8B2FA2B26BA5BFF31AB2A /* Pods_Runner.framework */; };
|
||||
82BD91202ADA6FBB0018E523 /* SharePasswordViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 82BD911F2ADA6FBB0018E523 /* SharePasswordViewController.m */; };
|
||||
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
|
||||
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
|
||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||
@ -39,6 +40,9 @@
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
82BD911E2ADA6FBB0018E523 /* SharePasswordViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharePasswordViewController.h; sourceTree = "<group>"; };
|
||||
82BD911F2ADA6FBB0018E523 /* SharePasswordViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SharePasswordViewController.m; sourceTree = "<group>"; };
|
||||
82BD91212ADA72360018E523 /* CommonDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonDefine.h; sourceTree = "<group>"; };
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
||||
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
||||
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@ -125,6 +129,9 @@
|
||||
97C146F11CF9000F007C117D /* Supporting Files */,
|
||||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
|
||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
||||
82BD911E2ADA6FBB0018E523 /* SharePasswordViewController.h */,
|
||||
82BD911F2ADA6FBB0018E523 /* SharePasswordViewController.m */,
|
||||
82BD91212ADA72360018E523 /* CommonDefine.h */,
|
||||
);
|
||||
path = Runner;
|
||||
sourceTree = "<group>";
|
||||
@ -287,6 +294,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
|
||||
82BD91202ADA6FBB0018E523 /* SharePasswordViewController.m in Sources */,
|
||||
97C146F31CF9000F007C117D /* main.m in Sources */,
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||
);
|
||||
|
||||
@ -1,11 +1,19 @@
|
||||
#import "AppDelegate.h"
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
#import "SharePasswordViewController.h"
|
||||
#import "CommonDefine.h"
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
/** 设置主控制器继承FlutterViewController*/
|
||||
SharePasswordViewController * VC = [[SharePasswordViewController alloc]init];
|
||||
UINavigationController * NVC = [[UINavigationController alloc]initWithRootViewController:VC];
|
||||
[self.window setRootViewController:NVC];
|
||||
/** flutter插件通道代理*/
|
||||
[GeneratedPluginRegistrant registerWithRegistry:self];
|
||||
|
||||
// Override point for customization after application launch.
|
||||
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<device id="retina6_12" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Flutter View Controller-->
|
||||
@ -14,13 +16,14 @@
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-26" y="-77"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
|
||||
20
star_lock/ios/Runner/CommonDefine.h
Normal file
20
star_lock/ios/Runner/CommonDefine.h
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// CommonDefine.h
|
||||
// Runner
|
||||
//
|
||||
// Created by DaisyWu on 2023/10/14.
|
||||
//
|
||||
|
||||
#ifndef CommonDefine_h
|
||||
#define CommonDefine_h
|
||||
|
||||
|
||||
/** 信号通道,须与flutter里一致*/
|
||||
#define flutterMethodChannel @"flutter_native_ios"
|
||||
/** 交互方法字段名,须与flutter里一致*/
|
||||
#define flutterMethodSharePassword @"flutter_sharePassword_to_ios"
|
||||
#define flutterMethodPresent @"flutter_present_to_ios"
|
||||
|
||||
|
||||
#endif /* CommonDefine_h */
|
||||
|
||||
16
star_lock/ios/Runner/SharePasswordViewController.h
Normal file
16
star_lock/ios/Runner/SharePasswordViewController.h
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// SharePasswordViewController.h
|
||||
// Runner
|
||||
//
|
||||
// Created by DaisyWu on 2023/10/14.
|
||||
//
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SharePasswordViewController : FlutterViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
103
star_lock/ios/Runner/SharePasswordViewController.m
Normal file
103
star_lock/ios/Runner/SharePasswordViewController.m
Normal file
@ -0,0 +1,103 @@
|
||||
//
|
||||
// SharePasswordViewController.m
|
||||
// Runner
|
||||
//
|
||||
// Created by DaisyWu on 2023/10/14.
|
||||
//
|
||||
|
||||
#import "SharePasswordViewController.h"
|
||||
#include "GeneratedPluginRegistrant.h"
|
||||
#import "CommonDefine.h"
|
||||
|
||||
|
||||
@interface SharePasswordViewController ()
|
||||
|
||||
@property(nonatomic,strong) FlutterMethodChannel* methodChannel;
|
||||
@property (nonatomic, copy) NSString *textToShare;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SharePasswordViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.textToShare = [[NSString alloc] init];
|
||||
|
||||
[self methodChannelFunction];
|
||||
}
|
||||
- (void)methodChannelFunction {
|
||||
|
||||
//创建 FlutterMethodChannel
|
||||
self.methodChannel = [FlutterMethodChannel
|
||||
methodChannelWithName:flutterMethodChannel binaryMessenger:self];
|
||||
//设置监听
|
||||
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||
// TODO
|
||||
NSString *method=call.method;
|
||||
if ([method isEqualToString:flutterMethodSharePassword]) {
|
||||
id params = call.arguments;
|
||||
self.textToShare = @"您好,您的密码是:";
|
||||
if ([params isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *paramDic = (NSDictionary *)params;
|
||||
//分享的标题
|
||||
self.textToShare = paramDic[@"pwdShareStr"];
|
||||
}
|
||||
//分享的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
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart';
|
||||
@ -26,6 +27,7 @@ class _PasswordKeyDetailPageState extends State<PasswordKeyDetailPage> {
|
||||
PasswordKeyListItem itemData = PasswordKeyListItem();
|
||||
late TextEditingController _inputPwdController;
|
||||
late TextEditingController _inputNameController;
|
||||
static const methodChannel = MethodChannel('flutter_native_ios');
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -33,14 +35,16 @@ class _PasswordKeyDetailPageState extends State<PasswordKeyDetailPage> {
|
||||
|
||||
_inputPwdController = TextEditingController();
|
||||
_inputNameController = TextEditingController();
|
||||
|
||||
// _initFluwx();
|
||||
}
|
||||
|
||||
// _initFluwx() async {
|
||||
// await registerWxApi(
|
||||
// appId: "", doOnAndroid: true, doOnIOS: true, universalLink: "");
|
||||
// }
|
||||
static Future<dynamic> tokNative(String method,
|
||||
{required Map arguments}) async {
|
||||
if (arguments == null) {
|
||||
return await methodChannel.invokeMethod(method);
|
||||
} else {
|
||||
return await methodChannel.invokeMethod(method, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -48,27 +52,6 @@ class _PasswordKeyDetailPageState extends State<PasswordKeyDetailPage> {
|
||||
if (obj != null && (obj["itemData"] != null)) {
|
||||
itemData = obj["itemData"];
|
||||
}
|
||||
List<String> nameItems = <String>[
|
||||
'微信',
|
||||
'朋友圈',
|
||||
'QQ',
|
||||
'QQ空间',
|
||||
'微博',
|
||||
'FaceBook',
|
||||
'邮件',
|
||||
'链接'
|
||||
];
|
||||
List<String> urlItems = <String>[
|
||||
'icon_wechat.png',
|
||||
'icon_wechat_moments.png',
|
||||
'icon_qq.png',
|
||||
'icon_qzone.png',
|
||||
'icon_sina.png',
|
||||
'icon_facebook.png',
|
||||
'icon_email.png',
|
||||
'icon_copylink.png'
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.mainBackgroundColor,
|
||||
appBar: TitleAppBar(
|
||||
@ -83,6 +66,13 @@ class _PasswordKeyDetailPageState extends State<PasswordKeyDetailPage> {
|
||||
width: 30.w,
|
||||
),
|
||||
onPressed: () {
|
||||
String pwdShareStr =
|
||||
'您好,您的密码是:${itemData.keyboardPwd}\n生效时间:${itemData.startDate}\n类型:永久\n锁名:${itemData.keyboardPwdName}';
|
||||
tokNative('flutter_sharePassword_to_ios',
|
||||
arguments: {'pwdShareStr': pwdShareStr}).then((result) {
|
||||
print('$result');
|
||||
});
|
||||
print('与原生交互');
|
||||
/*
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user