From d1c963796bd314fcc7aea0c9c921b273c45b974c Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Wed, 21 Jun 2023 16:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E8=B7=B3=E8=BD=AC=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=B8=A4=E4=B8=AA=E7=B1=BB=E5=9E=8B=EF=BC=9ACOUPON(12?= =?UTF-8?q?)=E4=BC=98=E6=83=A0=E5=88=B8=E5=88=97=E8=A1=A8=20CATE=5FBEAN(13?= =?UTF-8?q?)=E6=88=91=E7=9A=84=E5=8D=B0=E7=AB=A0=EF=BC=9B=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8F=8B=E7=9B=9F=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/build.gradle | 7 + lib/base_state.dart | 89 +++++--- lib/main_page.dart | 33 ++- pubspec.lock | 11 +- pubspec.yaml | 5 +- umeng_common_sdk-1.2.6/.gitignore | 15 ++ umeng_common_sdk-1.2.6/.metadata | 10 + umeng_common_sdk-1.2.6/CHANGELOG.md | 43 ++++ umeng_common_sdk-1.2.6/LICENSE | 1 + umeng_common_sdk-1.2.6/README.md | 14 ++ umeng_common_sdk-1.2.6/android/.gitignore | 8 + umeng_common_sdk-1.2.6/android/build.gradle | 40 ++++ .../android/gradle.properties | 3 + .../android/settings.gradle | 1 + .../android/src/main/AndroidManifest.xml | 3 + .../UmengCommonSdkPlugin.java | 214 ++++++++++++++++++ umeng_common_sdk-1.2.6/ios/.gitignore | 37 +++ umeng_common_sdk-1.2.6/ios/Assets/.gitkeep | 0 .../ios/Classes/UmengCommonSdkPlugin.h | 4 + .../ios/Classes/UmengCommonSdkPlugin.m | 102 +++++++++ .../ios/umeng_common_sdk.podspec | 26 +++ .../lib/umeng_common_sdk.dart | 57 +++++ umeng_common_sdk-1.2.6/pubspec.yaml | 64 ++++++ .../test/umeng_common_sdk_test.dart | 23 ++ 24 files changed, 770 insertions(+), 40 deletions(-) create mode 100644 umeng_common_sdk-1.2.6/.gitignore create mode 100644 umeng_common_sdk-1.2.6/.metadata create mode 100644 umeng_common_sdk-1.2.6/CHANGELOG.md create mode 100644 umeng_common_sdk-1.2.6/LICENSE create mode 100644 umeng_common_sdk-1.2.6/README.md create mode 100644 umeng_common_sdk-1.2.6/android/.gitignore create mode 100644 umeng_common_sdk-1.2.6/android/build.gradle create mode 100644 umeng_common_sdk-1.2.6/android/gradle.properties create mode 100644 umeng_common_sdk-1.2.6/android/settings.gradle create mode 100644 umeng_common_sdk-1.2.6/android/src/main/AndroidManifest.xml create mode 100644 umeng_common_sdk-1.2.6/android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java create mode 100644 umeng_common_sdk-1.2.6/ios/.gitignore create mode 100644 umeng_common_sdk-1.2.6/ios/Assets/.gitkeep create mode 100644 umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.h create mode 100644 umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.m create mode 100644 umeng_common_sdk-1.2.6/ios/umeng_common_sdk.podspec create mode 100644 umeng_common_sdk-1.2.6/lib/umeng_common_sdk.dart create mode 100644 umeng_common_sdk-1.2.6/pubspec.yaml create mode 100644 umeng_common_sdk-1.2.6/test/umeng_common_sdk_test.dart diff --git a/android/build.gradle b/android/build.gradle index 68071f47..a41d8a49 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -17,6 +17,7 @@ buildscript { } maven { url "https://www.jitpack.io" } maven {url 'https://developer.huawei.com/repo/'} + maven { url 'https://repo1.maven.org/maven2/' } } dependencies { @@ -25,6 +26,11 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.huawei.agconnect:agcp:1.4.1.300' classpath 'com.mob.sdk:MobSDK:+' + classpath 'com.android.tools.build:gradle:3.4.0' + classpath fileTree(include:['*.jar'], dir:'libs') + classpath 'com.umeng.umsdk:common:9.4.7' + classpath 'com.umeng.umsdk:asms:1.4.0' + classpath 'com.umeng.umsdk:abtest:1.0.0' } } @@ -46,6 +52,7 @@ allprojects { } maven { url "https://www.jitpack.io" } maven { url 'https://developer.huawei.com/repo/'} + maven { url 'https://repo1.maven.org/maven2/' } } } diff --git a/lib/base_state.dart b/lib/base_state.dart index 74dd3e55..421b4014 100644 --- a/lib/base_state.dart +++ b/lib/base_state.dart @@ -6,7 +6,6 @@ import 'package:shared_preferences/shared_preferences.dart'; abstract class BaseState extends State with WidgetsBindingObserver { - int lastTime = DateTime.now().millisecondsSinceEpoch; @override @@ -23,7 +22,7 @@ abstract class BaseState extends State break; case AppLifecycleState.resumed: //从后台切换前台,界面可见 pushRoute(); - if(DateTime.now().millisecondsSinceEpoch - lastTime > 300000) + if (DateTime.now().millisecondsSinceEpoch - lastTime > 300000) Navigator.of(context).popAndPushNamed('/router/main_page'); break; case AppLifecycleState.paused: // 界面不可见,后台 @@ -56,40 +55,58 @@ abstract class BaseState extends State String routeName = ""; Map params = {}; switch (pushMap["typed"].toString()) { - case "1":case "ARTICLE": - routeName = "/router/web_page"; - params["articleId"] = pushMap["info"]; - break; - case "2":case "ACTIVITY": - routeName = "/router/web_page"; - params["activityId"] = pushMap["info"]; - break; - case "3":case "SHOP": - routeName = "/router/store_order"; - params["id"] = pushMap["info"]; - params["tenant"] = pushMap["tenant"]; - params["storeName"] = pushMap["storeName"]; - break; - case "4":case "CREDIT_GOODS": - routeName = "/router/integral_store_page"; - params["goodsId"] = pushMap["info"]; - break; - case "5":case "ORDER": - routeName = "/router/order_details"; - params["id"] = pushMap["info"]; - break; - case "6":case "MEMBER": - routeName = "/router/community_details"; - params["businessId"] = pushMap["info"]; - break; - case "8":case "WALLET": - routeName = "/router/mine_wallet"; - params["id"] = pushMap["info"]; - break; - case "9":case "WELFARE": - routeName = "/router/welfare_page"; - params["id"] = pushMap["info"]; - break; + case "1": + case "ARTICLE": + routeName = "/router/web_page"; + params["articleId"] = pushMap["info"]; + break; + case "2": + case "ACTIVITY": + routeName = "/router/web_page"; + params["activityId"] = pushMap["info"]; + break; + case "3": + case "SHOP": + routeName = "/router/store_order"; + params["id"] = pushMap["info"]; + params["tenant"] = pushMap["tenant"]; + params["storeName"] = pushMap["storeName"]; + break; + case "4": + case "CREDIT_GOODS": + routeName = "/router/integral_store_page"; + params["goodsId"] = pushMap["info"]; + break; + case "5": + case "ORDER": + routeName = "/router/order_details"; + params["id"] = pushMap["info"]; + break; + case "6": + case "MEMBER": + routeName = "/router/community_details"; + params["businessId"] = pushMap["info"]; + break; + case "8": + case "WALLET": + routeName = "/router/mine_wallet"; + params["id"] = pushMap["info"]; + break; + case "9": + case "WELFARE": + routeName = "/router/welfare_page"; + params["id"] = pushMap["info"]; + break; + case "12": + case "COUPON": + routeName = "/router/coupon_page"; + params["id"] = pushMap["info"]; + break; + case "13": + case "CATE_BEAN": + routeName = "/router/trading_card_page"; + params["id"] = pushMap["info"]; + break; } sharedPreferences.setString("pushData", ""); print("xgPushClickAction: routeName: $routeName"); diff --git a/lib/main_page.dart b/lib/main_page.dart index 678a4389..a0fc31bd 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_bmflocation/flutter_bmflocation.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; @@ -33,6 +34,7 @@ import 'package:sharesdk_plugin/sharesdk_interface.dart'; import 'package:sharesdk_plugin/sharesdk_register.dart'; import 'package:tpns_flutter_plugin/android/xg_android_api.dart'; import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart'; +import 'package:umeng_common_sdk/umeng_common_sdk.dart'; import 'community/order_page.dart'; @@ -59,6 +61,7 @@ class _MainPage extends State with WidgetsBindingObserver { // List iconn; ApiService apiService; int lastTime = DateTime.now().millisecondsSinceEpoch; + String _platformVersion = 'Unknown'; @override void dispose() { @@ -111,6 +114,9 @@ class _MainPage extends State with WidgetsBindingObserver { ..dismissOnTap = false; initSdk(); + UmengCommonSdk.initCommon('6491509087568a379b5a1345', '6491509087568a379b5a1345', 'Umeng'); + UmengCommonSdk.setPageCollectionModeManual(); + initPlatformState(); pushRoute(); @@ -187,6 +193,21 @@ class _MainPage extends State with WidgetsBindingObserver { final XgFlutterPlugin xgFlutterPlugin = XgFlutterPlugin(); + Future initPlatformState() async { + String platformVersion; + try { + platformVersion = (await UmengCommonSdk.platformVersion); + } on PlatformException { + platformVersion = 'Failed to get platform version.'; + } + + if (!mounted) return; + + setState(() { + _platformVersion = platformVersion; + }); + } + initSdk() async { xgFlutterPlugin.stopXg(); @@ -247,7 +268,7 @@ class _MainPage extends State with WidgetsBindingObserver { ); } - /// @typed: ARTICLE(1)文章 ACTIVITY(2)活动 SHOP(3)店铺 CREDIT_GOODS(4)积分商品 ORDER(5)订单 TREND(6)动态 MEMBER(7)用户 WALLET(8)平台余额/钱包 WELFARE(9)福利中心 + /// @typed: ARTICLE(1)文章 ACTIVITY(2)活动 SHOP(3)店铺 CREDIT_GOODS(4)积分商品 ORDER(5)订单 TREND(6)动态 MEMBER(7)用户 WALLET(8)平台余额/钱包 WELFARE(9)福利中心 COUPON(12)优惠券列表 CATE_BEAN(13)我的印章 xgFlutterPlugin.addEventHandler(xgPushClickAction: (event) async { print("xgPushClickAction1: $event"); if (event["actionType"] == 2) return event; @@ -354,6 +375,16 @@ class _MainPage extends State with WidgetsBindingObserver { routeName = "/router/welfare_page"; params["id"] = pushMap["info"]; break; + case "12": + case "COUPON": + routeName = "/router/coupon_page"; + params["id"] = pushMap["info"]; + break; + case "13": + case "CATE_BEAN": + routeName = "/router/trading_card_page"; + params["id"] = pushMap["info"]; + break; } sharedPreferences.setString("pushData", ""); print("xgPushClickAction: routeName: $routeName"); diff --git a/pubspec.lock b/pubspec.lock index c46044e8..e71495c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -321,7 +321,7 @@ packages: name: fluwx url: "https://pub.flutter-io.cn" source: hosted - version: "3.13.1" + version: "3.9.0+2" font_awesome_flutter: dependency: "direct main" description: @@ -767,7 +767,7 @@ packages: name: tobias url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.2" + version: "2.4.1" tpns_flutter_plugin: dependency: "direct main" description: @@ -798,6 +798,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.3.2" + umeng_common_sdk: + dependency: "direct main" + description: + name: umeng_common_sdk + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.6" url_launcher: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 52eb1c90..9f5cffaf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: 一心回乡. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 3.2.14+58 +version: 3.2.16+60 environment: sdk: ">=2.7.0 <3.0.0" @@ -27,6 +27,7 @@ dependencies: url: https://github.com/TencentCloud/TPNS-Flutter-Plugin ref: V1.1.6 + umeng_common_sdk: ^1.2.3 like_button: ^2.0.2 cupertino_icons: ^1.0.2 flutter_swiper: ^1.1.6 @@ -143,3 +144,5 @@ flutter: flutter_intl: enabled: true + +umeng_common_sdk:path: umeng_common_sdk-1.2.6 diff --git a/umeng_common_sdk-1.2.6/.gitignore b/umeng_common_sdk-1.2.6/.gitignore new file mode 100644 index 00000000..4e2c7044 --- /dev/null +++ b/umeng_common_sdk-1.2.6/.gitignore @@ -0,0 +1,15 @@ +.DS_Store +.dart_tool/ + +.packages +.pub/ +example/.flutter-plugins-dependencies +example/ios/Flutter/flutter_export_environment.sh +**/pubspec.lock + +build/ +.idea/ +**/.idea/ +**/gradle/ +**/gradlew +**/gradlew.bat \ No newline at end of file diff --git a/umeng_common_sdk-1.2.6/.metadata b/umeng_common_sdk-1.2.6/.metadata new file mode 100644 index 00000000..70a9f943 --- /dev/null +++ b/umeng_common_sdk-1.2.6/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 9b2d32b605630f28625709ebd9d78ab3016b2bf6 + channel: stable + +project_type: plugin diff --git a/umeng_common_sdk-1.2.6/CHANGELOG.md b/umeng_common_sdk-1.2.6/CHANGELOG.md new file mode 100644 index 00000000..b0ba85c0 --- /dev/null +++ b/umeng_common_sdk-1.2.6/CHANGELOG.md @@ -0,0 +1,43 @@ +##1.2.6 +-Android端plugin插件项目依赖的common包版本升级到9.5.6,asms包版本升级到1.6.3。 +-Android端example工程增加MyApp类文件,将UMConfigure.preInit函数放到MyApp类中io.flutter.app.FlutterApplication +.onCreate生命周期函数中执行。 + +##1.2.5 +-Android 稳定性优化; + +##1.2.4 +-Android 上下文获取优化; + +##1.2.3 +-Android 依赖库asms更新1.4.1; + +##1.2.2 +-Android 依赖更新;初始化简化; + +##1.2.1 +-Android Example工程初始化优化; + +##1.2.0 +-支持空安全; + +##1.1.3 +-Android Example工程优化;Android依赖库迁移maven center; + +##1.1.2 +-Android Example工程添加release包混淆规则 + +##1.1.1 +-Android依赖库改为线上maven形式 + +##1.1.0 +-优化描述,同步友盟+官方下载flutter插件 + +## 0.0.3 +-example工程完善基础组件初始化 + +## 0.0.2 +-同步最新友盟+common库 + +## 0.0.1 +-初始提交 diff --git a/umeng_common_sdk-1.2.6/LICENSE b/umeng_common_sdk-1.2.6/LICENSE new file mode 100644 index 00000000..e84282a4 --- /dev/null +++ b/umeng_common_sdk-1.2.6/LICENSE @@ -0,0 +1 @@ +Add your license here. diff --git a/umeng_common_sdk-1.2.6/README.md b/umeng_common_sdk-1.2.6/README.md new file mode 100644 index 00000000..2805b8c7 --- /dev/null +++ b/umeng_common_sdk-1.2.6/README.md @@ -0,0 +1,14 @@ +# umeng_common_sdk Flutter Plugin + +# 安装 + +在工程 pubspec.yaml 中加入 dependencies + +dependencies: + umeng_common_sdk: 1.2.6 + +# 使用 + +import 'package:umeng_common_sdk/umeng_common_sdk.dart'; + +**注意** : 需要先调用 UMConfigure.init 来初始化插件(Appkey可在统计后台 “管理->应用管理->应用列表” 页面查看,或在 “我的产品”选择某应用->设置->应用信息 查看Appkey),才能保证其他功能正常工作。 \ No newline at end of file diff --git a/umeng_common_sdk-1.2.6/android/.gitignore b/umeng_common_sdk-1.2.6/android/.gitignore new file mode 100644 index 00000000..c6cbe562 --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/umeng_common_sdk-1.2.6/android/build.gradle b/umeng_common_sdk-1.2.6/android/build.gradle new file mode 100644 index 00000000..2439e6cc --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/build.gradle @@ -0,0 +1,40 @@ +group 'com.umeng.umeng_common_sdk' +version '1.0' + +buildscript { + repositories { + google() + jcenter() + maven { url 'https://repo1.maven.org/maven2/'} + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.5.0' + } +} + +rootProject.allprojects { + repositories { + google() + jcenter() + maven { url 'https://repo1.maven.org/maven2/'} + } +} + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 29 + + defaultConfig { + minSdkVersion 16 + } + lintOptions { + disable 'InvalidPackage' + } +} + +dependencies { + api 'com.umeng.umsdk:common:9.5.6'// 必选 + api 'com.umeng.umsdk:asms:1.6.3'// 必选 +} \ No newline at end of file diff --git a/umeng_common_sdk-1.2.6/android/gradle.properties b/umeng_common_sdk-1.2.6/android/gradle.properties new file mode 100644 index 00000000..94adc3a3 --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/umeng_common_sdk-1.2.6/android/settings.gradle b/umeng_common_sdk-1.2.6/android/settings.gradle new file mode 100644 index 00000000..7a33a47e --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'umeng_common_sdk' diff --git a/umeng_common_sdk-1.2.6/android/src/main/AndroidManifest.xml b/umeng_common_sdk-1.2.6/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..1c05ffd6 --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/umeng_common_sdk-1.2.6/android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java b/umeng_common_sdk-1.2.6/android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java new file mode 100644 index 00000000..4c6e17a0 --- /dev/null +++ b/umeng_common_sdk-1.2.6/android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java @@ -0,0 +1,214 @@ +package com.umeng.umeng_common_sdk; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.umeng.analytics.MobclickAgent; +import com.umeng.commonsdk.UMConfigure; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; + +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.PluginRegistry.Registrar; + +/** UmengCommonSdkPlugin */ +public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private MethodChannel channel; + + public static void registerWith(Registrar registrar) { + final MethodChannel channel = new MethodChannel(registrar.messenger(), "umeng_common_sdk"); + UmengCommonSdkPlugin plugin = new UmengCommonSdkPlugin(); + plugin.mContext = registrar.context(); + channel.setMethodCallHandler(plugin); + onAttachedEngineAdd(); + } + + private static void onAttachedEngineAdd() { +// add by umeng + try { + Class agent = Class.forName("com.umeng.analytics.MobclickAgent"); + Method[] methods = agent.getDeclaredMethods(); + for (Method m : methods) { + android.util.Log.e("UMLog", "Reflect:"+m); + if(m.getName().equals("onEventObject")) { + versionMatch = true; + break; + } + } + if(!versionMatch) { + android.util.Log.e("UMLog", "安卓SDK版本过低,建议升级至8以上"); + //return; + } + else { + android.util.Log.e("UMLog", "安卓依赖版本检查成功"); + } + } + catch (Exception e) { + e.printStackTrace(); + android.util.Log.e("UMLog", "SDK版本过低,请升级至8以上"+e.toString()); + return; + } + + Method method = null; + try { + Class config = Class.forName("com.umeng.commonsdk.UMConfigure"); + method = config.getDeclaredMethod("setWraperType", String.class, String.class); + method.setAccessible(true); + method.invoke(null, "flutter","1.0"); + android.util.Log.i("UMLog", "setWraperType:flutter1.0 success"); + } + catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + android.util.Log.e("UMLog", "setWraperType:flutter1.0"+e.toString()); + } + } + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + mContext = flutterPluginBinding.getApplicationContext(); + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "umeng_common_sdk"); + channel.setMethodCallHandler(this); + onAttachedEngineAdd(); + } + + private static Context mContext = null; + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + if(!versionMatch) { + android.util.Log.e("UMLog", "onMethodCall:"+call.method+":安卓SDK版本过低,请升级至8以上"); + //return; + } + try { + List args = (List) call.arguments; + switch (call.method) { + case "getPlatformVersion": + result.success("Android " + android.os.Build.VERSION.RELEASE); + break; + case "initCommon": + initCommon(args); + break; + case "onEvent": + onEvent(args); + break; + case "onProfileSignIn": + onProfileSignIn(args); + break; + case "onProfileSignOff": + onProfileSignOff(); + break; + case "setPageCollectionModeAuto": + setPageCollectionModeAuto(); + break; + case "setPageCollectionModeManual": + setPageCollectionModeManual(); + break; + case "onPageStart": + onPageStart(args); + break; + case "onPageEnd": + onPageEnd(args); + break; + case "reportError": + reportError(args); + break; + default: + result.notImplemented(); + break; + } + } catch (Exception e) { + e.printStackTrace(); + android.util.Log.e("Umeng", "Exception:"+e.getMessage()); + } + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } + + private static Boolean versionMatch = false; + + public static void setContext (Context ctx) { + mContext = ctx; + } + + public static Context getContext () { + return mContext; + } + + private void initCommon(List args) { + String appkey = (String)args.get(0); + String channel = (String)args.get(2); + UMConfigure.init(getContext(), appkey, channel, UMConfigure.DEVICE_TYPE_PHONE, null); + android.util.Log.i("UMLog", "initCommon:"+appkey+"@"+channel); + } + + private void onEvent(List args) { + String event = (String)args.get(0); + Map map = null ; + if(args.size()>1) { + map = (Map) args.get(1); + } + //JSONObject properties = new JSONObject(map); + MobclickAgent.onEventObject(getContext(), event, map); + + if(map!=null) { +// android.util.Log.i("UMLog", "onEventObject:"+event+"("+map.toString()+")"); + } + else { +// android.util.Log.i("UMLog", "onEventObject:"+event); + } + } + + private void onProfileSignIn (List args) { + String userID = (String)args.get(0); + MobclickAgent.onProfileSignIn(userID); + android.util.Log.i("UMLog", "onProfileSignIn:"+userID); + } + + private void onProfileSignOff () { + MobclickAgent.onProfileSignOff(); + android.util.Log.i("UMLog", "onProfileSignOff"); + } + + private void setPageCollectionModeAuto () { + MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO); + android.util.Log.i("UMLog", "setPageCollectionModeAuto"); + } + + private void setPageCollectionModeManual () { + MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL); + android.util.Log.i("UMLog", "setPageCollectionModeManual"); + } + + private void onPageStart(List args) { + String event = (String)args.get(0); + MobclickAgent.onPageStart(event); + android.util.Log.i("UMLog", "onPageStart:"+event); + } + + private void onPageEnd(List args) { + String event = (String)args.get(0); + MobclickAgent.onPageEnd(event); + android.util.Log.i("UMLog", "onPageEnd:"+event); + } + + private void reportError(List args){ + String error = (String)args.get(0); + MobclickAgent.reportError(getContext(), error); + android.util.Log.i("UMLog", "reportError:"+error); + } +} diff --git a/umeng_common_sdk-1.2.6/ios/.gitignore b/umeng_common_sdk-1.2.6/ios/.gitignore new file mode 100644 index 00000000..aa479fd3 --- /dev/null +++ b/umeng_common_sdk-1.2.6/ios/.gitignore @@ -0,0 +1,37 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/umeng_common_sdk-1.2.6/ios/Assets/.gitkeep b/umeng_common_sdk-1.2.6/ios/Assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.h b/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.h new file mode 100644 index 00000000..a3c1e373 --- /dev/null +++ b/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface UmengCommonSdkPlugin : NSObject +@end diff --git a/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.m b/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.m new file mode 100644 index 00000000..057855e2 --- /dev/null +++ b/umeng_common_sdk-1.2.6/ios/Classes/UmengCommonSdkPlugin.m @@ -0,0 +1,102 @@ +#import "UmengCommonSdkPlugin.h" +#import +#import + +@interface UMengflutterpluginForUMCommon : NSObject +@end +@implementation UMengflutterpluginForUMCommon + ++ (BOOL)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result{ + BOOL resultCode = YES; + if ([@"initCommon" isEqualToString:call.method]){ + NSArray* arguments = (NSArray *)call.arguments; + NSString* appkey = arguments[1]; + NSString* channel = arguments[2]; + [UMConfigure initWithAppkey:appkey channel:channel]; + //result(@"success"); + } + else{ + resultCode = NO; + } + return resultCode; +} +@end + +@interface UMengflutterpluginForAnalytics : NSObject +@end +@implementation UMengflutterpluginForAnalytics : NSObject + ++ (BOOL)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result{ + BOOL resultCode = YES; + NSArray* arguments = (NSArray *)call.arguments; + if ([@"onEvent" isEqualToString:call.method]){ + NSString* eventName = arguments[0]; + NSDictionary* properties = arguments[1]; + [MobClick event:eventName attributes:properties]; + //result(@"success"); + } + else if ([@"onProfileSignIn" isEqualToString:call.method]){ + NSString* userID = arguments[0]; + [MobClick profileSignInWithPUID:userID]; + //result(@"success"); + } + else if ([@"onProfileSignOff" isEqualToString:call.method]){ + [MobClick profileSignOff]; + //result(@"success"); + } + else if ([@"setPageCollectionModeAuto" isEqualToString:call.method]){ + [MobClick setAutoPageEnabled:YES]; + //result(@"success"); + } + else if ([@"setPageCollectionModeManual" isEqualToString:call.method]){ + [MobClick setAutoPageEnabled:NO]; + //result(@"success"); + } + else if ([@"onPageStart" isEqualToString:call.method]){ + NSString* pageName = arguments[0]; + [MobClick beginLogPageView:pageName]; + //result(@"success"); + } + else if ([@"onPageEnd" isEqualToString:call.method]){ + NSString* pageName = arguments[0]; + [MobClick endLogPageView:pageName]; + //result(@"success"); + } + else if ([@"reportError" isEqualToString:call.method]){ + NSLog(@"reportError API not existed "); + //result(@"success"); + } + else{ + resultCode = NO; + } + return resultCode; +} + +@end + +@implementation UmengCommonSdkPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:@"umeng_common_sdk" + binaryMessenger:[registrar messenger]]; + UmengCommonSdkPlugin* instance = [[UmengCommonSdkPlugin alloc] init]; + [registrar addMethodCallDelegate:instance channel:channel]; +} + +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + if ([@"getPlatformVersion" isEqualToString:call.method]) { + result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); + } else { + //result(FlutterMethodNotImplemented); + } + + BOOL resultCode = [UMengflutterpluginForUMCommon handleMethodCall:call result:result]; + if (resultCode) return; + + resultCode = [UMengflutterpluginForAnalytics handleMethodCall:call result:result]; + if (resultCode) return; + + result(FlutterMethodNotImplemented); +} + +@end diff --git a/umeng_common_sdk-1.2.6/ios/umeng_common_sdk.podspec b/umeng_common_sdk-1.2.6/ios/umeng_common_sdk.podspec new file mode 100644 index 00000000..9640954d --- /dev/null +++ b/umeng_common_sdk-1.2.6/ios/umeng_common_sdk.podspec @@ -0,0 +1,26 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint umeng_common_sdk.podspec' to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'umeng_common_sdk' + s.version = '0.0.1' + s.summary = 'A new Flutter plugin.' + s.description = <<-DESC +A new Flutter plugin. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + s.platform = :ios, '8.0' + s.dependency 'UMCommon' + s.dependency 'UMDevice' + s.static_framework = true + + # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } +end diff --git a/umeng_common_sdk-1.2.6/lib/umeng_common_sdk.dart b/umeng_common_sdk-1.2.6/lib/umeng_common_sdk.dart new file mode 100644 index 00000000..e6da3c18 --- /dev/null +++ b/umeng_common_sdk-1.2.6/lib/umeng_common_sdk.dart @@ -0,0 +1,57 @@ + +import 'dart:async'; + +import 'package:flutter/services.dart'; + +class UmengCommonSdk { + static const MethodChannel _channel = + const MethodChannel('umeng_common_sdk'); + + static Future get platformVersion async { + final String version = await _channel.invokeMethod('getPlatformVersion'); + return version; + } + + static Future initCommon(String androidAppkey, String iosAppkey, String channel) async { + List params = [androidAppkey, iosAppkey ,channel]; + final dynamic result = await _channel.invokeMethod('initCommon', params); + return result; + } + + static void onEvent(String event, Map properties) { + List args = [event,properties]; + _channel.invokeMethod('onEvent', args); + } + + static void onProfileSignIn (String userID) { + List args = [userID]; + _channel.invokeMethod('onProfileSignIn', args); + } + + static void onProfileSignOff () { + _channel.invokeMethod('onProfileSignOff'); + } + + static void setPageCollectionModeManual() { + _channel.invokeMethod('setPageCollectionModeManual'); + } + + static void onPageStart(String viewName) { + List args = [viewName]; + _channel.invokeMethod('onPageStart', args); + } + + static void onPageEnd(String viewName) { + List args = [viewName]; + _channel.invokeMethod('onPageEnd', args); + } + + static void setPageCollectionModeAuto() { + _channel.invokeMethod('setPageCollectionModeAuto'); + } + + static void reportError(String error) { + List args = [error]; + _channel.invokeMethod('reportError', args); + } +} diff --git a/umeng_common_sdk-1.2.6/pubspec.yaml b/umeng_common_sdk-1.2.6/pubspec.yaml new file mode 100644 index 00000000..0785ad5f --- /dev/null +++ b/umeng_common_sdk-1.2.6/pubspec.yaml @@ -0,0 +1,64 @@ +name: umeng_common_sdk +description: 友盟+组件化基础库:Common Flutter plugin(Android & iOS). +version: 1.2.6 +homepage: https://www.umeng.com + +environment: + sdk: '>=2.12.0 <3.0.0' + flutter: ">=1.10.0" + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' and Android 'package' identifiers should not ordinarily + # be modified. They are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + platforms: + android: + package: com.umeng.umeng_common_sdk + pluginClass: UmengCommonSdkPlugin + ios: + pluginClass: UmengCommonSdkPlugin + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware. + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/umeng_common_sdk-1.2.6/test/umeng_common_sdk_test.dart b/umeng_common_sdk-1.2.6/test/umeng_common_sdk_test.dart new file mode 100644 index 00000000..8e5b1052 --- /dev/null +++ b/umeng_common_sdk-1.2.6/test/umeng_common_sdk_test.dart @@ -0,0 +1,23 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:umeng_common_sdk/umeng_common_sdk.dart'; + +void main() { + const MethodChannel channel = MethodChannel('umeng_common_sdk'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await UmengCommonSdk.platformVersion, '42'); + }); +}