Skip to content

Commit

Permalink
feat: Set custom SDK name and version on CleverTap
Browse files Browse the repository at this point in the history
  • Loading branch information
einsteinx2 committed Jan 5, 2024
1 parent 10cdd17 commit 2e5f596
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
Expand Down Expand Up @@ -70,4 +72,4 @@ KitsExample

# Swift Package Manager
Package.resolved
.build
.build
2 changes: 0 additions & 2 deletions Cartfile

This file was deleted.

4 changes: 0 additions & 4 deletions Cartfile.private

This file was deleted.

14 changes: 14 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use_frameworks!

target 'mParticle-CleverTap' do
pod 'mParticle-Apple-SDK', '~> 8'
pod 'CleverTap-iOS-SDK', '~> 5.2'
end

target 'mParticle_CleverTapTests' do
pod 'mParticle-Apple-SDK', '~> 8'
pod 'CleverTap-iOS-SDK', '~> 5.2'
pod 'Quick'
pod 'Nimble'
pod 'OCMock'
end
6 changes: 4 additions & 2 deletions Scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ NOTES="$2"
# Update version number
#

# Update constant in codebase
sed -i '' 's/NSString \*const kLibVersion = @".*/NSString *const kLibVersion = @"'"$VERSION"'";/' mParticle-CleverTap/MPKitCleverTap.m

# Update CocoaPods podspec file
sed -i '' 's/\(^ s.version[^=]*= \).*/\1"'"$VERSION"'"/' mParticle-CleverTap.podspec

# Make the release commit in git
#

git add mParticle-CleverTap.podspec
git add mParticle_CleverTap.json
git add CHANGELOG.md
git add mParticle-CleverTap/MPKitCleverTap.m
git commit -m "chore(release): $VERSION [skip ci]
$NOTES"
146 changes: 110 additions & 36 deletions mParticle-CleverTap.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion mParticle-CleverTap/MPKitCleverTap.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
NSString *const ctCleverTapIdIntegrationKey = @"clevertap_id_integration_setting";
NSString *const kCTTransactionID = @"Transaction Id";
NSString *const kCTChargedID = @"Charged ID";
NSString *const kLibName = @"mParticle-iOS";
NSString *const kLibVersion = @"8.2.0";

@implementation MPKitCleverTap

Expand Down Expand Up @@ -46,10 +48,12 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
- (void)start {
static dispatch_once_t kitPredicate;
dispatch_once(&kitPredicate, ^{
NSString *accountID = [self->_configuration objectForKey:ctAccountID ];
NSString *accountID = [self->_configuration objectForKey:ctAccountID];
NSString *accountToken = [self->_configuration objectForKey:ctAccountToken];
NSString *region = [self->_configuration objectForKey:ctRegion];
[CleverTap setCredentialsWithAccountID:accountID token:accountToken region:region];
[[CleverTap sharedInstance] setLibrary:kLibName];
[[CleverTap sharedInstance] setCustomSdkVersion:kLibName version:[self.class intVersion:kLibVersion]];
[[CleverTap sharedInstance] notifyApplicationLaunchedWithOptions:nil];

self->_started = YES;
Expand Down Expand Up @@ -273,4 +277,16 @@ - (MPKitExecStatus *)setOptOut:(BOOL)optOut {
return [self execStatus:MPKitReturnCodeSuccess];
}

#pragma mark Private
+ (int)intVersion:(NSString *)version {
NSArray *split = [version componentsSeparatedByString:@"."];
if (split.count != 3) {
// Something went wrong (this should never happen), so return a default
return 0;
}

NSString *string = [NSString stringWithFormat:@"%02d%02d%02d", [split[0] intValue], [split[1] intValue], [split[2] intValue]];
return [string intValue];
}

@end
41 changes: 41 additions & 0 deletions mParticle_CleverTapTests/mParticle_VersionToIntTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// mParticle_VersionToIntTest.m
// mParticle_CleverTapTests
//
// Created by Ben Baron on 1/5/24.
// Copyright © 2024 mParticle. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "MPKitCleverTap.h"

@interface MPKitCleverTap()
+ (int)intVersion:(NSString *)version;
@end

@interface mParticle_VersionToIntTest : XCTestCase
@end

@implementation mParticle_VersionToIntTest

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testVersionToInt {
XCTAssertEqual([MPKitCleverTap intVersion:@"8.2.0"], 80200);
XCTAssertEqual([MPKitCleverTap intVersion:@"8.5.10"], 80510);
XCTAssertEqual([MPKitCleverTap intVersion:@"8.10.14"], 81014);
XCTAssertEqual([MPKitCleverTap intVersion:@"9.0.0"], 90000);
XCTAssertEqual([MPKitCleverTap intVersion:@"9.0"], 0);
XCTAssertEqual([MPKitCleverTap intVersion:@"9"], 0);
XCTAssertEqual([MPKitCleverTap intVersion:@"9.0.0.0"], 0);
XCTAssertEqual([MPKitCleverTap intVersion:@"10.123.5"], 1012305);
}


@end

0 comments on commit 2e5f596

Please sign in to comment.