Last updated:
0 purchases
flutter sharetrace huaji
flutter_sharetrace_huaji #
请先从ShareTrace控制台获取AppKey
一、安装 #
1.1 添加依赖
在项目的pubspec.yaml文件中添加以下内容:
dependencies:
flutter_sharetrace_huaji: ^0.1.0
copied to clipboard
1.2 安装
通过命令行安装
flutter pub get
copied to clipboard
二、配置 #
Android配置
找到项目的AndroidManifest.xml文件,在<application>...</application>中增加以下配置
<meta-data
android:name="com.sharetrace.APP_KEY"
android:value="SHARETRACE_APPKEY"/>
copied to clipboard
请将 SHARETRACE_APPKEY 替换成 sharetrace 为应用分配的 appkey
iOS配置
在Info.plist中增加以下配置
<key>com.sharetrace.APP_KEY</key>
<string> SHARETRACE_APPKEY </string>
copied to clipboard
请将 SHARETRACE_APPKEY 替换成 sharetrace 为应用分配的 appkey
三、获取安装携带的参数 #
3.1. 导入接口定义
import 'package:flutter_sharetrace_huaji/flutter_sharetrace_huaji.dart';
copied to clipboard
3.2. 定义结果回调
Future responseHandler(Map<String, String> data) async {
setState(() {
result = "getInstallTrace: \n\n"
+ "code= " + data['code'] + "\n"
+ "msg= " + data['msg'] + "\n"
+ "paramsData= " + data['paramsData'] + "\n"
+ "channel= " + data['channel'];
});
}
copied to clipboard
3.3. 请求获取参数
FlutterSharetraceHuaji _sharetraceFlutterPlugin = FlutterSharetraceHuaji.getInstance();
_sharetraceFlutterPlugin.getInstallTrace(responseHandler);
copied to clipboard
3.4. 初始化
FlutterSharetraceHuaji _sharetraceFlutterPlugin = FlutterSharetraceHuaji.getInstance();
_sharetraceFlutterPlugin.initSharetrace();
copied to clipboard
四、一键调起 #
Sharetrace支持通过标准的Scheme和Universal Links(iOS>=9),接入Sharetrace SDK后,在各种浏览器,包括微信,微博等内置浏览器一键调起app,并传递网页配置等自定义动态参数。配置只需简单几个步骤即可,如下:
4.1 开启一键调起功能
登录Sharetrace的管理后台,找到iOS配置,开启相关功能和填入配置
其中Team Id可以在Apple开发者后台查看
4.2 开启Associated Domains服务
方法一(推荐):Xcode一键开启
(这里以Xcode 12为例,其他Xcode版本类似)
在如下图所示位置填入Sharetrace后台提供的applinks
方法二:通过Apple开发者管理后台手动开启
登录到Apple管理后台,在Identifiers找到所需开启到App ID
4.3 Scheme配置
找到项目Info配置,填入后台分配的Scheme, 如下图:
4.4 代码配置
从Sharetrace flutter plugin 1.4.0 开始,一键调起逻辑由插件内部处理以解决与其他插件冲突的问题,则可以跳过该步骤。
若plugin版本 < 1.4.0,依然需要在AppDelegate进行配置,如下所示:
iOS 配置
找到AppDelegate文件,参考以下配置
Objective-C
#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
#import <flutter_sharetrace_huaji/flutter_sharetrace_huaji.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
// Universal Link
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
[FlutterSharetraceHuaji handleUniversalLink:userActivity];
//其他代码
return YES;
}
//iOS9以下 Scheme
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[FlutterSharetraceHuaji handleSchemeLinkURL:url];
//其他代码
return YES;
}
//iOS9以上 Scheme
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(nonnull NSDictionary *)options {
[FlutterSharetraceHuaji handleSchemeLinkURL:url];
//其他代码
return YES;
}
@end
copied to clipboard
Swift
import UIKit
import Flutter
import flutter_sharetrace_huaji
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
FlutterSharetraceHuaji.handleSchemeLinkURL(url)
return true
}
override func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
FlutterSharetraceHuaji.handleSchemeLinkURL(url)
return true
}
override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
FlutterSharetraceHuaji.handleUniversalLink(userActivity)
return true
}
}
copied to clipboard
4.5 获取一键调起参数
class _MyAppState extends State<MyApp> {
String result;
FlutterSharetraceHuaji _sharetraceFlutterPlugin;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
_sharetraceFlutterPlugin = FlutterSharetraceHuaji.getInstance();
_sharetraceFlutterPlugin.initSharetrace();
_sharetraceFlutterPlugin.registerWakeupHandler(wakeupHandler);
setState(() {
result = "";
});
}
Future wakeupHandler(Map<String, String> data) async {
setState(() {
result = "wakeupTrace: \n\n"
+ "code= " + data['code'] + "\n"
+ "msg= " + data['msg'] + "\n"
+ "paramsData= " + data['paramsData'] + "\n"
+ "channel= " + data['channel'];
});
}
}
copied to clipboard
五、配置安装方式 #
SDK 集成完成后,按照sharetrace控制台接入流程完成后续的配置。
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.