Skip to content

Commit

Permalink
feat: Protobuf 模块支持 SwiftPM 集成 (#248)
Browse files Browse the repository at this point in the history
* feat: Protobuf 模块支持 SwiftPM 集成

* test: demo 兼容 GrowingToolsKit SPM 集成方式

* test: demo 中 移除 C++ 相关文件的编译,测试 SPM 集成时,其将导致编译报错

* ci: fix protobuf test import path

* test: Protobuf(SwiftPM) 兼容 GrowingToolsKit 展示

* fix: SwiftPM Module Hybrid public headers path

* fix: swift protobuf bug

* fix: swift protobuf 兼容 hybrid 事件内的 attributes

* ci: delete PR template

* test: update Podfile.lock

* test: update ci

* refactor: delete GrowingTrackerCore_cdp in Package.swift

* Revert "fix: swift project building error about 'Include of non-modular header inside framework module' (#251)"

This reverts commit 4ad2838.

* fix: dataSourceId 非空校验

* test: update demo

* test: update ci

* test: update ci

* fix: protobuf toJsonObject remove pageName and operatingSystem

* fix: update swiftProtobuf module

* fix: protobuf module remove using of __has_include
  • Loading branch information
YoloMao committed May 31, 2023
1 parent 50f24c8 commit a643854
Show file tree
Hide file tree
Showing 30 changed files with 1,661 additions and 334 deletions.
20 changes: 0 additions & 20 deletions .github/pull_request_template.md

This file was deleted.

6 changes: 1 addition & 5 deletions Example/Example.xcodeproj/project.pbxproj
Expand Up @@ -76,7 +76,6 @@
04A6FAF524E67215006C72F0 /* GIOBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A6FAF424E67215006C72F0 /* GIOBaseViewController.m */; };
04F675662628293800077374 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F675652628293800077374 /* AdSupport.framework */; };
33A0F692F1D1738D6854E19A /* Pods_HostApplicationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */; };
34106BB428FECB0E00E7DB01 /* Crasher.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34106BB328FECB0E00E7DB01 /* Crasher.mm */; };
34486D3D27B1049000FA8223 /* UITapGestureRecognizerAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34486D3B27B102B000FA8223 /* UITapGestureRecognizerAutotrackTest.m */; };
34664587278EEEA6009C351C /* A0GrowingAnalyticsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 047BF3A224F638BB0028FE94 /* A0GrowingAnalyticsTest.m */; };
346E0B3B29F2724400A12E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346E0B3A29F2724400A12E4E /* AppDelegate.swift */; };
Expand Down Expand Up @@ -112,7 +111,6 @@
349975FC28BF303B00466640 /* AdServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 349975F728BF300F00466640 /* AdServices.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
349B529228C088F100EE88FE /* AdvertTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 349B528528C086C600EE88FE /* AdvertTest.m */; };
349DA46828F2BD5400C4281F /* Others.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 349DA46728F2BC5400C4281F /* Others.storyboard */; };
349DA46C28F2BF9400C4281F /* GIOCrashMonitorTableViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349DA46B28F2BF9400C4281F /* GIOCrashMonitorTableViewController.mm */; };
349F1488285B503B00437F53 /* GIODefaultWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 349F1484285B503A00437F53 /* GIODefaultWebViewController.m */; };
349F1489285B503B00437F53 /* GIOH5BrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 349F1487285B503A00437F53 /* GIOH5BrowserViewController.m */; };
349F148C285B52B700437F53 /* GIOScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 349F148B285B52B700437F53 /* GIOScanViewController.m */; };
Expand Down Expand Up @@ -2143,7 +2141,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-ProtobufTests/Pods-ProtobufTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-c1567d15/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-61b6cda4/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
);
Expand Down Expand Up @@ -2373,7 +2371,6 @@
04A6FAF524E67215006C72F0 /* GIOBaseViewController.m in Sources */,
0465315A24DD4272002D254C /* GIOFoodTableViewCell.m in Sources */,
0465314524DD4272002D254C /* GIOCustomEventViewController.m in Sources */,
349DA46C28F2BF9400C4281F /* GIOCrashMonitorTableViewController.mm in Sources */,
0465314724DD4272002D254C /* GIOContainerViewController.m in Sources */,
0465314E24DD4272002D254C /* GIOLabelAttributeViewController.m in Sources */,
349F1488285B503B00437F53 /* GIODefaultWebViewController.m in Sources */,
Expand All @@ -2385,7 +2382,6 @@
0465314324DD4272002D254C /* GIOClickEventViewController.m in Sources */,
349F148C285B52B700437F53 /* GIOScanViewController.m in Sources */,
3494DD092859CCF300A6CE46 /* GrowingDeepLinkHandler+XCTest.m in Sources */,
34106BB428FECB0E00E7DB01 /* Crasher.mm in Sources */,
4916270F24E157BB00444AF2 /* GIOPresentViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
9 changes: 6 additions & 3 deletions Example/Example/AppDelegate.m
Expand Up @@ -8,7 +8,13 @@

#import "AppDelegate.h"
#import <AppTrackingTransparency/AppTrackingTransparency.h>

#if __has_include(<GrowingToolsKit/GrowingToolsKit.h>)
#import <GrowingToolsKit/GrowingToolsKit.h>
#else
#import "GrowingToolsKit.h"
#endif

//#import <Bugly/Bugly.h>

@interface AppDelegate ()
Expand Down Expand Up @@ -39,10 +45,7 @@ - (void)SDK3rdStart {
GrowingSDKConfiguration *configuration = [GrowingSDKConfiguration configurationWithProjectId:@"0a1b4118dd954ec3bcc69da5138bdb96"];
configuration.debugEnabled = YES;
configuration.idMappingEnabled = YES;

#if defined(SDKCDP)
configuration.dataSourceId = @"ab555003531e0fd1";
#endif

#if defined(SDKADVERTMODULE)
configuration.ASAEnabled = YES;
Expand Down
Expand Up @@ -23,7 +23,7 @@ @implementation GIOClickEventViewController
- (void)viewDidLoad {
[super viewDidLoad];
#if defined(AUTOTRACKER)
#if !defined(SDKCDP) && defined(SDK3rd)
#if defined(SDK3rd)
self.growingPageAttributes = @{@"greet": @"hello"};
#endif
#endif
Expand Down
Expand Up @@ -24,7 +24,7 @@ @implementation GIOMeasurementProtocolTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
#if defined(AUTOTRACKER)
#if !defined(SDKCDP) && defined(SDK3rd)
#if defined(SDK3rd)
self.growingPageAttributes = @{@"xxx" : @"111mmm"};
#endif
#endif
Expand Down
Expand Up @@ -30,7 +30,7 @@ - (void)didReceiveMemoryWarning {

- (void)configRandomPageAttributes {
#if defined(AUTOTRACKER)
#if !defined(SDKCDP) && defined(SDK3rd)
#if defined(SDK3rd)
self.growingPageAttributes = [self getRandomAttributes];
#endif
#endif
Expand All @@ -44,7 +44,7 @@ - (IBAction)setPageAttributesOutRangeBtnClick:(UIButton *)sender {

NSDictionary *pval = [GIOConstants getLargeDictionary];
#if defined(AUTOTRACKER)
#if !defined(SDKCDP) && defined(SDK3rd)
#if defined(SDK3rd)
self.growingPageAttributes = pval;
#endif
#endif
Expand Down
1 change: 1 addition & 0 deletions Example/GrowingAnalyticsTests/A0GrowingAnalyticsCDPTest.m
Expand Up @@ -46,6 +46,7 @@ @implementation A0GrowingAnalyticsCDPTest

+ (void)setUp {
GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"];
configuration.dataSourceId = @"test";
configuration.idMappingEnabled = YES;
configuration.sessionInterval = 10.0f;
configuration.urlScheme = @"growing.xctest";
Expand Down
7 changes: 4 additions & 3 deletions Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m
Expand Up @@ -33,6 +33,7 @@ @implementation A0GrowingAnalyticsTest

+ (void)setUp {
GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"];
configuration.dataSourceId = @"test";
configuration.idMappingEnabled = YES;
configuration.sessionInterval = 10.0f;
configuration.urlScheme = @"growing.xctest";
Expand Down Expand Up @@ -353,7 +354,7 @@ - (void)testTrackTimer {

GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject;
XCTAssertEqualObjects(event.eventName, @"eventName");
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.9); // sleep 不准
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准
}

{
Expand Down Expand Up @@ -389,7 +390,7 @@ - (void)testTrackTimer {

GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject;
XCTAssertEqualObjects(event.eventName, @"eventName");
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.9); // sleep 不准
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准
// 不会算上前后台切换的时间
XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 2.0);
}
Expand Down Expand Up @@ -474,7 +475,7 @@ - (void)testTrackTimerWithAttributes {
GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject;
XCTAssertEqualObjects(event.eventName, @"eventName");
XCTAssertEqualObjects(event.attributes[@"key"], @"value");
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.9); // sleep 不准
XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准
}

{
Expand Down
Expand Up @@ -52,6 +52,11 @@ - (void)testGrowingTrackerStart {
@"GrowingTracker未初始化");

GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"xctest"];
XCTAssertThrowsSpecificNamed([GrowingTracker startWithConfiguration:config launchOptions:nil],
NSException,
@"初始化异常");

config.dataSourceId = @"xctest";
[GrowingTracker startWithConfiguration:config launchOptions:nil];

[GrowingDispatchManager dispatchInGrowingThread:^{
Expand All @@ -72,6 +77,11 @@ - (void)testGrowingAutotrackerStart {
@"GrowingAutotracker未初始化");

GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"xctest"];
XCTAssertThrowsSpecificNamed([GrowingAutotracker startWithConfiguration:config launchOptions:nil],
NSException,
@"初始化异常");

config.dataSourceId = @"xctest";
[GrowingAutotracker startWithConfiguration:config launchOptions:nil];

[GrowingDispatchManager dispatchInGrowingThread:^{
Expand Down
Expand Up @@ -46,6 +46,7 @@ - (void)tearDown {

- (void)test00SendActivateEvent {
GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"];
configuration.dataSourceId = @"test";
configuration.urlScheme = @"growing.530c8231345c492d";
[GrowingAutotracker startWithConfiguration:configuration launchOptions:nil];

Expand Down
Expand Up @@ -22,7 +22,7 @@
#import "Modules/Protobuf/GrowingEventProtobufPersistence.h"
#import "GrowingTrackerCore/Event/GrowingCustomEvent.h"
#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h"
#import "Modules/Protobuf/Events/GrowingBaseEvent+Protobuf.h"
#import "Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h"

@interface ProtobufPersistenceTest : XCTestCase

Expand Down
Expand Up @@ -46,6 +46,8 @@ @implementation EventTest

+ (void)setUp {
GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"test"];
config.dataSourceId = @"test";

// 避免不执行readPropertyInTrackThread
config.dataCollectionEnabled = YES;
// 开启idMapping
Expand Down
5 changes: 0 additions & 5 deletions GrowingAutotracker-cdp/GrowingAutotracker.h
Expand Up @@ -17,15 +17,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if __has_feature(modules)
@import UIKit;
@import GrowingAnalytics;
#else
#import <UIKit/UIKit.h>
#import "GrowingAttributesBuilder.h"
#import "GrowingAutotrackConfiguration.h"
#import "GrowingDynamicProxy.h"
#endif

NS_ASSUME_NONNULL_BEGIN

Expand Down
4 changes: 4 additions & 0 deletions GrowingAutotracker-cdp/GrowingAutotracker.m
Expand Up @@ -42,6 +42,10 @@ + (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launch
if (!configuration.projectId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil];
}

if (!configuration.dataSourceId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil];
}

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down
4 changes: 4 additions & 0 deletions GrowingAutotracker/GrowingAutotracker.m
Expand Up @@ -42,6 +42,10 @@ + (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launch
if (!configuration.projectId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil];
}

if (!configuration.dataSourceId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil];
}

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down
4 changes: 0 additions & 4 deletions GrowingTracker-cdp/GrowingTracker.h
Expand Up @@ -17,13 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if __has_feature(modules)
@import GrowingAnalytics;
#else
#import "GrowingAttributesBuilder.h"
#import "GrowingDynamicProxy.h"
#import "GrowingTrackConfiguration.h"
#endif

NS_ASSUME_NONNULL_BEGIN

Expand Down
4 changes: 4 additions & 0 deletions GrowingTracker-cdp/GrowingTracker.m
Expand Up @@ -42,6 +42,10 @@ + (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launch
if (!configuration.projectId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil];
}

if (!configuration.dataSourceId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil];
}

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down
4 changes: 4 additions & 0 deletions GrowingTracker/GrowingTracker.m
Expand Up @@ -42,6 +42,10 @@ + (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launch
if (!configuration.projectId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil];
}

if (!configuration.dataSourceId.length) {
@throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil];
}

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down

0 comments on commit a643854

Please sign in to comment.