From 2773fce27c2b64a4236a91cf3c52c707a96c255b Mon Sep 17 00:00:00 2001 From: xiaoyu Date: Fri, 10 May 2024 15:05:43 +0800 Subject: [PATCH] 集成ios友盟相关配置 --- ios/Runner.xcodeproj/project.pbxproj | 16 ++++++++++++++++ ios/Runner/AppDelegate.swift | 5 +++++ ios/Runner/Runner-Bridging-Header.h | 19 ++++++++++++++++++- ios/Runner/UMeng/UMAnalyticsSwift.swift | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ios/Runner/UMeng/UMCommonSwift.swift | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 ios/Runner/UMeng/UMAnalyticsSwift.swift create mode 100644 ios/Runner/UMeng/UMCommonSwift.swift diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index b12e312..f2d6a59 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -243,6 +243,8 @@ B891A8EA2BD257F4006CB06E /* RatePromptHandler_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = B891A8E82BD257F4006CB06E /* RatePromptHandler_ios.mm */; }; B891A8ED2BD25AFE006CB06E /* AniSoundUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B891A8EC2BD25AFE006CB06E /* AniSoundUtils.cpp */; }; B891A8EF2BD26895006CB06E /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B891A8EE2BD26895006CB06E /* StoreKit.framework */; }; + B89EC5202BEDF60B00ABE22D /* UMAnalyticsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89EC51E2BEDF60A00ABE22D /* UMAnalyticsSwift.swift */; }; + B89EC5212BEDF60B00ABE22D /* UMCommonSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89EC51F2BEDF60B00ABE22D /* UMCommonSwift.swift */; }; F5FCE34FB9E028C20A7850DE /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A3DBEAB6142776646A34D9C /* Pods_RunnerTests.framework */; }; FB8AFCB0A8C34B5508A68F45 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DEBBC1D861BE053F3ECE0B9 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ @@ -930,6 +932,8 @@ B891A8EB2BD25AFE006CB06E /* AniSoundUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AniSoundUtils.h; sourceTree = ""; }; B891A8EC2BD25AFE006CB06E /* AniSoundUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AniSoundUtils.cpp; sourceTree = ""; }; B891A8EE2BD26895006CB06E /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + B89EC51E2BEDF60A00ABE22D /* UMAnalyticsSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UMAnalyticsSwift.swift; sourceTree = ""; }; + B89EC51F2BEDF60B00ABE22D /* UMCommonSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UMCommonSwift.swift; sourceTree = ""; }; D63F3847140160A2204489BA /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; D8C046A1A9C279FDBB5C174E /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; F04D1DAE6591EAD461CBBE9A /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; @@ -1013,6 +1017,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + B89EC51C2BEDF5E500ABE22D /* UMeng */, B891A25D2BCD102C006CB06E /* Wowgame */, 52450AF22A4ED0EC007B3E4B /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, @@ -1585,6 +1590,15 @@ path = NativeIOS; sourceTree = ""; }; + B89EC51C2BEDF5E500ABE22D /* UMeng */ = { + isa = PBXGroup; + children = ( + B89EC51E2BEDF60A00ABE22D /* UMAnalyticsSwift.swift */, + B89EC51F2BEDF60B00ABE22D /* UMCommonSwift.swift */, + ); + path = UMeng; + sourceTree = ""; + }; E653501EF99460B1BB76C5EE /* Frameworks */ = { isa = PBXGroup; children = ( @@ -1986,6 +2000,7 @@ B891A8422BD24EFB006CB06E /* AniLayoutObject.cpp in Sources */, B891A8DC2BD24EFB006CB06E /* HValueStorage.cpp in Sources */, B891A8832BD24EFB006CB06E /* ToyContainerSprite.cpp in Sources */, + B89EC5202BEDF60B00ABE22D /* UMAnalyticsSwift.swift in Sources */, B891A8D62BD24EFB006CB06E /* HStringUtils.cpp in Sources */, B891A8772BD24EFB006CB06E /* MapAdventureObjectPickupItem.cpp in Sources */, B891A8A02BD24EFB006CB06E /* ToyResourcesConfig.cpp in Sources */, @@ -2152,6 +2167,7 @@ B891A8722BD24EFB006CB06E /* IMapImageObject.cpp in Sources */, B891A8C82BD24EFB006CB06E /* HParentalGateShowInterface.cpp in Sources */, B891A8202BD24EFB006CB06E /* StaticActionParser.cpp in Sources */, + B89EC5212BEDF60B00ABE22D /* UMCommonSwift.swift in Sources */, B891A8502BD24EFB006CB06E /* AniPickLevelScene.cpp in Sources */, B891A8732BD24EFB006CB06E /* ISpriteAnimator.cpp in Sources */, B891A8462BD24EFB006CB06E /* AniLevelView.cpp in Sources */, diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 590eee9..c3366f2 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -7,6 +7,11 @@ import Flutter _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + + // umeng初始化 + UMCommonSwift.setLogEnabled(bFlag: true); + UMCommonSwift.initWithAppkey(appKey: "663b66b0b3362515012f4ea5", channel: "App Store"); + GeneratedPluginRegistrant.register(with: self) let controller : FlutterViewController = window?.rootViewController as! FlutterViewController _ = VoiceXSMessageChannel(messager: controller.binaryMessenger) diff --git a/ios/Runner/Runner-Bridging-Header.h b/ios/Runner/Runner-Bridging-Header.h index 6d5a9fb..e03a5ed 100644 --- a/ios/Runner/Runner-Bridging-Header.h +++ b/ios/Runner/Runner-Bridging-Header.h @@ -1,6 +1,23 @@ -#import "GeneratedPluginRegistrant.h" + +#ifndef Runner_Bridging_Header_h +#define Runner_Bridging_Header_h + +// SingSound #import +// UMCommon +#import +#import +#import + +// UMAPM +#import +#import +#import + + +#import "GeneratedPluginRegistrant.h" #import "WowGameCocosManager.h" +#endif /* Runner_Bridging_Header_h */ diff --git a/ios/Runner/UMeng/UMAnalyticsSwift.swift b/ios/Runner/UMeng/UMAnalyticsSwift.swift new file mode 100644 index 0000000..dd5ed50 --- /dev/null +++ b/ios/Runner/UMeng/UMAnalyticsSwift.swift @@ -0,0 +1,256 @@ +// +// UMAnalyticsSwift.swift +// swiftDemo +// +// Created by wangkai on 2019/8/30. +// Copyright © 2019 wangkai. All rights reserved. +// + +import Foundation +import CoreLocation + +class UMAnalyticsSwift: NSObject { + + + //页面统计 + /** 手动页面时长统计, 记录某个页面展示的时长. + @param pageName 统计的页面名称. + @param seconds 单位为秒,int型. + @return void. + */ + static func logPageView(pageName:String,seconds:Int){ + MobClick.logPageView(pageName, seconds:Int32(seconds)); + } + + /** 自动页面时长统计, 开始记录某个页面展示时长. + 使用方法:必须配对调用beginLogPageView:和endLogPageView:两个函数来完成自动统计,若只调用某一个函数不会生成有效数据。 + 在该页面展示时调用beginLogPageView:,当退出该页面时调用endLogPageView: + @param pageName 统计的页面名称. + @return void. + */ + static func beginLogPageView(pageName:String){ + MobClick.beginLogPageView(pageName); + } + + /** 自动页面时长统计, 结束记录某个页面展示时长. + 使用方法:必须配对调用beginLogPageView:和endLogPageView:两个函数来完成自动统计,若只调用某一个函数不会生成有效数据。 + 在该页面展示时调用beginLogPageView:,当退出该页面时调用endLogPageView: + @param pageName 统计的页面名称. + @return void. + */ + static func endLogPageView(pageName:String){ + MobClick.endLogPageView(pageName); + } + + //事件统计 + /** 自定义事件,数量统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID + + @param eventId 网站上注册的事件Id. + @param label 分类标签。不同的标签会分别进行统计,方便同一事件的不同标签的对比,为nil或空字符串时后台会生成和eventId同名的标签. + @param accumulation 累加值。为减少网络交互,可以自行对某一事件ID的某一分类标签进行累加,再传入次数作为参数。 + @return void. + */ + static func event(eventId:String){ + MobClick.event(eventId); + } + /** 自定义事件,数量统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID + */ + // label为nil或@""时,等同于 event:eventId label:eventId; + static func event(eventId:String,label:String){ + MobClick.event(eventId, label: label); + } + + /** 自定义事件,数量统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID + */ + static func event(eventId:String,attributes:Dictionary){ + MobClick.event(eventId, attributes:attributes); + } + + static func event(eventId:String,attributes:Dictionary,counter:Int){ + MobClick.event(eventId, attributes: attributes, counter: Int32(counter)); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + beginEvent,endEvent要配对使用,也可以自己计时后通过durations参数传递进来 + + @param eventId 网站上注册的事件Id. + @param label 分类标签。不同的标签会分别进行统计,方便同一事件的不同标签的对比,为nil或空字符串时后台会生成和eventId同名的标签. + @param primarykey 这个参数用于和event_id一起标示一个唯一事件,并不会被统计;对于同一个事件在beginEvent和endEvent 中要传递相同的eventId 和 primarykey + @param millisecond 自己计时需要的话需要传毫秒进来 + @return void. + + @warning 每个event的attributes不能超过10个 + eventId、attributes中key和value都不能使用空格和特殊字符,必须是NSString,且长度不能超过255个字符(否则将截取前255个字符) + id, ts, du是保留字段,不能作为eventId及key的名称 + */ + static func beginEvent(eventId:String){ + MobClick.beginEvent(eventId); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func endEvent(eventId:String){ + MobClick.endEvent(eventId); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func beginEvent(eventId:String,label:String){ + MobClick.beginEvent(eventId, label: label); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func endEvent(eventId:String,label:String){ + MobClick.endEvent(eventId, label: label); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func beginEvent(eventId:String,primarykey:String,attributes:Dictionary){ + MobClick.beginEvent(eventId, primarykey: primarykey, attributes: attributes); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func endEvent(eventId:String,primarykey:String){ + MobClick.endEvent(eventId, primarykey: primarykey); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func event(eventId:String,durations:Int){ + MobClick.event(eventId, durations: Int32(durations)) + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func event(eventId:String,label:String,millisecond:Int){ + MobClick.event(eventId, label: label, durations: Int32(millisecond)); + } + + /** 自定义事件,时长统计. + 使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. + */ + static func event(eventId:String,attributes:Dictionary,millisecond:Int){ + MobClick.event(eventId, attributes: attributes, durations: Int32(millisecond)); + } + + + /** active user sign-in. + 使用sign-In函数后,如果结束该PUID的统计,需要调用sign-Off函数 + @param puid : user's ID + @param provider : 不能以下划线"_"开头,使用大写字母和数字标识; 如果是上市公司,建议使用股票代码。 + @return void. + */ + static func profileSignInWithPUID(puid:String){ + MobClick.profileSignIn(withPUID: puid); + } + static func profileSignInWithPUID(puid:String,provider:String){ + MobClick.profileSignIn(withPUID:puid, provider: provider); + } + + /** active user sign-off. + 停止sign-in PUID的统计 + @return void. + */ + static func profileSignOff(){ + MobClick.profileSignOff(); + } + + ///--------------------------------------------------------------------------------------- + /// @name 地理位置设置 + /// 需要链接 CoreLocation.framework 并且 #import + ///--------------------------------------------------------------------------------------- + + /** 设置经纬度信息 + @param latitude 纬度. + @param longitude 经度. + @return void + */ + static func setLatitude(latitude:Double,longitude:Double){ + MobClick.setLatitude(latitude, longitude: longitude); + } + + + ///--------------------------------------------------------------------------------------- + /// @name Utility函数 + ///--------------------------------------------------------------------------------------- + + /** 判断设备是否越狱,依据是否存在apt和Cydia.app + */ + static func isJailbroken() -> Bool{ + return MobClick.isJailbroken(); + } + + /** 判断App是否被破解 + */ + static func isPirated() -> Bool{ + return MobClick.isPirated(); + } + + + + /** + * 设置预置事件属性 键值对 会覆盖同名的key + */ + static func registerPreProperties(property:Dictionary) + { + MobClick.registerPreProperties(property); + } + + /** + * + * 删除指定预置事件属性 + @param key + */ + static func unregisterPreProperty(propertyName:String) + { + MobClick.unregisterPreProperty(propertyName); + } + + /** + * 获取预置事件所有属性;如果不存在,则返回空。 + */ + static func getPreProperties() -> Dictionary + { + return MobClick.getPreProperties() as! Dictionary ; + } + + /** + *清空所有预置事件属性。 + */ + static func clearPreProperties() + { + MobClick.clearPreProperties(); + } + + + /** + * 设置关注事件是否首次触发,只关注eventList前五个合法eventID.只要已经保存五个,此接口无效 + */ + static func setFirstLaunchEvent(eventList:Array) + { + MobClick.setFirstLaunchEvent(eventList); + } + + /** 设置是否自动采集页面, 默认NO(不自动采集). + @param value 设置为YES, umeng SDK 会将自动采集页面信息 + */ + static func setAutoPageEnabled(value:Bool) + { + MobClick.setAutoPageEnabled(value); + } + +} diff --git a/ios/Runner/UMeng/UMCommonSwift.swift b/ios/Runner/UMeng/UMCommonSwift.swift new file mode 100644 index 0000000..d6d1ce1 --- /dev/null +++ b/ios/Runner/UMeng/UMCommonSwift.swift @@ -0,0 +1,60 @@ +// +// UMCommonSwift.swift +// swiftDemo +// +// Created by wangkai on 2019/8/29. +// Copyright © 2019 wangkai. All rights reserved. +// + +import Foundation +import OpenGLES + + +class UMCommonSwift: NSObject { + + /** 初始化友盟所有组件产品 + @param appKey 开发者在友盟官网申请的appkey. + @param channel 渠道标识,可设置nil表示"App Store". + */ + static func initWithAppkey(appKey:String,channel:String){ + let config = UMAPMConfig.default(); + + config.crashAndBlockMonitorEnable = true; + config.launchMonitorEnable = true; + config.memMonitorEnable = true; + config.oomMonitorEnable = true; + config.networkEnable = true; + config.javaScriptBridgeEnable = true; + config.pageMonitorEnable = true; + + UMCrashConfigure.setAPMConfig(config); + UMConfigure.initWithAppkey(appKey, channel: channel); + UMConfigure.setLogEnabled(true); + + } + + /** 设置是否在console输出sdk的log信息. + @param bFlag 默认NO(不输出log); 设置为YES, 输出可供调试参考的log信息. 发布产品时必须设置为NO. + */ + static func setLogEnabled(bFlag:Bool){ + UMConfigure.setLogEnabled(bFlag); + } + + /** 设置是否对日志信息进行加密, 默认NO(不加密). + @param value 设置为YES, umeng SDK 会将日志信息做加密处理 + */ + static func setEncryptEnabled(value:Bool){ + UMConfigure.setEncryptEnabled(value); + } + + static func umidString() -> String{ + return UMConfigure.umidString(); + } + + /** + 集成测试需要device_id + */ + static func deviceIDForIntegration() -> String{ + return UMConfigure.deviceIDForIntegration(); + } +} -- libgit2 0.22.2