Skip to content

Commit

Permalink
[Bugfix] Version & Build for Application Installed and `Application…
Browse files Browse the repository at this point in the history
… Updated`
  • Loading branch information
desusai7 committed Jun 22, 2022
1 parent 4399392 commit b4ee337
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ All notable changes to this project will be documented in this file.
## Version - 1.6.0 - 2022-05-04
### Feature
- Flush API

## Version - 1.6.1 - 2022-06-20
- Included Build Number as well in the life cycle events Application Installed & Application Updated.
- Accepting path as well as part of the url for both control plane url and data plane url.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center">
<a href="https://cocoapods.org/pods/Rudder">
<img src="https://img.shields.io/cocoapods/v/Rudder.svg?style=flat">
<img src="https://img.shields.io/static/v1?label=pod&message=v1.6.1&color=blue&style=flat">
</a>
</p>

Expand Down Expand Up @@ -39,15 +39,15 @@ The iOS SDK is available through [**CocoaPods**](https://cocoapods.org), [**Cart
To install the SDK, simply add the following line to your Podfile:

```xcode
pod 'Rudder', '1.6.0'
pod 'Rudder', '1.6.1'
```

### Carthage

For Carthage support, add the following line to your `Cartfile`:

```xcode
github "rudderlabs/rudder-sdk-ios" "v1.6.0"
github "rudderlabs/rudder-sdk-ios" "v1.6.1"
```

> Remember to include the following code in all `.m` and `.h` files where you want to refer to or use the RudderStack SDK classes, as shown:
Expand All @@ -71,7 +71,7 @@ You can also add the RudderStack iOS SDK via Swift Package Mangaer, via one of t

* Enter the package repository (`git@github.com:rudderlabs/rudder-sdk-ios.git`) in the search bar.

* In **Dependency Rule**, select **Up to Next Major Version** and enter `1.6.0` as the value, as shown:
* In **Dependency Rule**, select **Up to Next Major Version** and enter `1.6.1` as the value, as shown:

![Setting dependency](https://user-images.githubusercontent.com/59817155/145574696-8c849749-13e0-40d5-aacb-3fccb5c8e67d.png)

Expand Down Expand Up @@ -99,7 +99,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "git@github.com:rudderlabs/rudder-sdk-ios.git", from: "1.6.0")
.package(url: "git@github.com:rudderlabs/rudder-sdk-ios.git", from: "1.6.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion Rudder.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Rudder'
s.version = "1.6.0"
s.version = "1.6.1"
s.summary = "Privacy and Security focused Segment-alternative. iOS ,tvOS and watchOS SDK"
s.description = <<-DESC
Rudder is a platform for collecting, storing and routing customer event data to dozens of tools. Rudder is open-source, can run in your cloud environment (AWS, GCP, Azure or even your data-centre) and provides a powerful transformation framework to process your event data on the fly.
Expand Down
4 changes: 2 additions & 2 deletions Rudder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.3;
MARKETING_VERSION = 1.6.1;
PRODUCT_BUNDLE_IDENTIFIER = com.rudderstack.Rudder;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1055,7 +1055,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.3;
MARKETING_VERSION = 1.6.1;
PRODUCT_BUNDLE_IDENTIFIER = com.rudderstack.Rudder;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
13 changes: 11 additions & 2 deletions Sources/Classes/Public/RSPreferenceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ extern NSString *const RSOptOutTimeKey;
- (void) saveTraits: (NSString* __nonnull) traits;
- (NSString* __nonnull) getTraits;

- (NSString* __nullable) getBuildVersionCode;
- (void) saveBuildVersionCode: (NSString* __nonnull) versionCode;
- (void) saveBuildVersionCode:(NSString* __nonnull)versionCode;
- (NSString* __nullable) getBuildVersionCode;
- (void) deleteBuildVersionCode;

- (void) performMigration;

- (NSString* __nullable) getBuildNumber;
- (void) saveBuildNumber: (NSString* __nonnull) buildNumber;

- (NSString* __nullable) getVersionNumber;
- (void) saveVersionNumber: (NSString* __nonnull) versionNumber;

- (NSString* __nullable) getExternalIds;
- (void) saveExternalIds: (NSString* __nonnull) externalIdsJson;
Expand Down
1 change: 1 addition & 0 deletions Sources/Classes/Public/RSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSArray*) serializeArray: (NSArray*) array;
+ (int) getNumberOfBatches:(RSDBMessage*) dbMessage withFlushQueueSize: (int) queueSize;
+ (NSMutableArray<NSString *>*) getBatch:(NSMutableArray<NSString *>*) messageDetails withQueueSize: (int) queueSize;
+ (BOOL) isValidURL:(NSURL*) url;

extern unsigned int MAX_EVENT_SIZE;
extern unsigned int MAX_BATCH_SIZE;
Expand Down
39 changes: 14 additions & 25 deletions Sources/Classes/RSConfigBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
#import "RSConfigBuilder.h"
#import "RSLogger.h"
#import "RSConstants.h"
#import "RSUtils.h"

@implementation RSConfigBuilder

- (instancetype) withEndPointUrl:(NSString *)endPointUrl{
- (instancetype) withEndPointUrl:(NSString *) endPointUrl{
if (config == nil) {
config = [[RSConfig alloc] init];
}
NSURL *url = [[NSURL alloc] initWithString:endPointUrl];
if ([url port]) {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@:%@", [url scheme], [url host], [url port]];
} else {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [url scheme], [url host]];
if([RSUtils isValidURL:url]) {
config.dataPlaneUrl = url.absoluteString;
}
return self;
}
Expand All @@ -31,10 +30,8 @@ - (instancetype) withDataPlaneUrl: (NSString*) dataPlaneUrl {
}

NSURL *url = [[NSURL alloc] initWithString:dataPlaneUrl];
if ([url port]) {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@:%@", [url scheme], [url host], [url port]];
} else {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [url scheme], [url host]];
if([RSUtils isValidURL:url]) {
config.dataPlaneUrl = url.absoluteString;
}
return self;
}
Expand All @@ -43,10 +40,8 @@ - (instancetype)withDataPlaneURL:(NSURL *) dataPlaneURL {
if (config == nil) {
config = [[RSConfig alloc] init];
}
if ([dataPlaneURL port]) {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@:%@", [dataPlaneURL scheme], [dataPlaneURL host] ,[dataPlaneURL port]];
} else {
config.dataPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [dataPlaneURL scheme], [dataPlaneURL host]];
if([RSUtils isValidURL:dataPlaneURL]) {
config.dataPlaneUrl = dataPlaneURL.absoluteString;
}
return self;
}
Expand Down Expand Up @@ -146,11 +141,9 @@ -(instancetype)withConfigPlaneUrl:(NSString *) configPlaneUrl {
config = [[RSConfig alloc] init];
}
NSURL *url = [[NSURL alloc] initWithString:configPlaneUrl];
if([url path]){
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@%@", [url scheme], [url host], [url path]];
return self;
if([RSUtils isValidURL:url]) {
config.controlPlaneUrl = url.absoluteString;
}
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [url scheme], [url host]];
return self;
}

Expand All @@ -159,23 +152,19 @@ - (instancetype)withControlPlaneUrl:(NSString *) controlPlaneUrl {
config = [[RSConfig alloc] init];
}
NSURL *url = [[NSURL alloc] initWithString:controlPlaneUrl];
if([url path]){
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@%@", [url scheme], [url host], [url path]];
return self;
if([RSUtils isValidURL:url]) {
config.controlPlaneUrl = url.absoluteString;
}
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [url scheme], [url host]];
return self;
}

- (instancetype)withControlPlaneURL:(NSURL *) controlPlaneURL {
if (config == nil) {
config = [[RSConfig alloc] init];
}
if([controlPlaneURL path]){
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@%@", [controlPlaneURL scheme], [controlPlaneURL host], [controlPlaneURL path]];
return self;
if([RSUtils isValidURL:controlPlaneURL]) {
config.controlPlaneUrl = controlPlaneURL.absoluteString;
}
config.controlPlaneUrl = [[NSString alloc] initWithFormat:@"%@://%@", [controlPlaneURL scheme], [controlPlaneURL host]];
return self;
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Classes/RSConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ @implementation RSConstants
bool const RSTrackLifeCycleEvents = YES;
bool const RSRecordScreenViews = NO;
bool const RSEnableBackgroundMode = NO;
NSString *const RS_VERSION = @"1.6.0";
NSString *const RS_VERSION = @"1.6.1";
NSString* const DISABLE = @"disable";
NSString* const WHITELISTED_EVENTS = @"whitelistedEvents";
NSString* const BLACKLISTED_EVENTS = @"blacklistedEvents";
Expand Down
21 changes: 15 additions & 6 deletions Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (instancetype)init : (NSString*) _writeKey config:(RSConfig*) _config {

[RSLogger logDebug:@"EventRepository: initiating preferenceManager"];
self->preferenceManager = [RSPreferenceManager getInstance];
[self->preferenceManager performMigration];

[RSLogger logDebug:@"EventRepository: initiating processor and factories"];
[self __initiateSDK];
Expand Down Expand Up @@ -621,20 +622,28 @@ - (void)_applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if (!self->config.trackLifecycleEvents) {
return;
}
NSString *previousVersion = [preferenceManager getBuildVersionCode];
NSString *previousVersion = [preferenceManager getVersionNumber];
NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];

NSString* previousBuildNumber = [preferenceManager getBuildNumber];
NSString *currentBuildNumber = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

if (!previousVersion) {
[[RSClient sharedInstance] track:@"Application Installed" properties:@{
@"version": currentVersion
@"version": currentVersion,
@"build": currentBuildNumber
}];
[preferenceManager saveBuildVersionCode:currentVersion];
} else if (![currentVersion isEqualToString:previousVersion]) {
[preferenceManager saveVersionNumber:currentVersion];
[preferenceManager saveBuildNumber:currentBuildNumber];
} else if (![previousVersion isEqualToString:currentVersion]) {
[[RSClient sharedInstance] track:@"Application Updated" properties:@{
@"previous_version" : previousVersion ?: @"",
@"version": currentVersion
@"version": currentVersion,
@"previous_build": previousBuildNumber ?: @"",
@"build": currentBuildNumber
}];
[preferenceManager saveBuildVersionCode:currentVersion];
[preferenceManager saveVersionNumber:currentVersion];
[preferenceManager saveBuildNumber:currentBuildNumber];
}

NSMutableDictionary *applicationOpenedProperties = [[NSMutableDictionary alloc] init];
Expand Down
38 changes: 38 additions & 0 deletions Sources/Classes/RSPreferenceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#import "RSPreferenceManager.h"
#import "RSLogger.h"
#if TARGET_OS_WATCH
#import <WatchKit/WKInterfaceDevice.h>
#endif
Expand All @@ -18,6 +19,8 @@ @implementation RSPreferenceManager
NSString *const RSServerConfigKey = @"rl_server_config";
NSString *const RSServerLastUpdatedKey = @"rl_server_last_updated";
NSString *const RSTraitsKey = @"rl_traits";
NSString *const RSApplicationBuildKey = @"rl_application_build_key";
NSString *const RSApplicationVersionKey = @"rl_application_version_key";
NSString *const RSApplicationInfoKey = @"rl_application_info_key";
NSString *const RSExternalIdKey = @"rl_external_id";
NSString *const RSAnonymousIdKey = @"rl_anonymous_id";
Expand Down Expand Up @@ -64,6 +67,11 @@ - (NSString *)getTraits {
return [[NSUserDefaults standardUserDefaults] valueForKey:RSTraitsKey];
}

- (NSString* __nullable) getBuildNumber {
return [[NSUserDefaults standardUserDefaults] valueForKey:RSApplicationBuildKey];
}

// saving the version number to the NSUserDefaults
- (void)saveBuildVersionCode:(NSString *)versionCode {
[[NSUserDefaults standardUserDefaults] setValue:versionCode forKey:RSApplicationInfoKey];
[[NSUserDefaults standardUserDefaults] synchronize];
Expand All @@ -73,6 +81,27 @@ - (NSString *)getBuildVersionCode {
return [[NSUserDefaults standardUserDefaults] valueForKey:RSApplicationInfoKey];
}

- (void) deleteBuildVersionCode {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:RSApplicationInfoKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

// saving the build number to the NSUserDefaults
- (void) saveBuildNumber: (NSString* __nonnull) buildNumber {
[[NSUserDefaults standardUserDefaults] setValue:buildNumber forKey:RSApplicationBuildKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

// saving the version number to the NSUserDefaults
- (NSString* __nullable) getVersionNumber {
return [[NSUserDefaults standardUserDefaults] valueForKey:RSApplicationVersionKey];
}

- (void) saveVersionNumber: (NSString* __nonnull) versionNumber {
[[NSUserDefaults standardUserDefaults] setValue:versionNumber forKey:RSApplicationVersionKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getExternalIds {
return [[NSUserDefaults standardUserDefaults] valueForKey:RSExternalIdKey];
}
Expand Down Expand Up @@ -145,4 +174,13 @@ - (long)getOptOutTime {
}
}

- (void) performMigration {
NSString* versionNumber = [self getBuildVersionCode];
if(versionNumber != nil) {
[RSLogger logDebug:[[NSString alloc] initWithFormat:@"RSPreferenceManager: performMigration: buildNumber stored in %@ key, migrating it to %@", RSApplicationInfoKey, RSApplicationBuildKey]];
[self deleteBuildVersionCode];
[self saveVersionNumber:versionNumber];
}
}

@end
4 changes: 4 additions & 0 deletions Sources/Classes/RSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ + (int) getNumberOfBatches:(RSDBMessage*) dbMessage withFlushQueueSize: (int) qu
return [messageDetails subarrayWithRange:NSMakeRange(0, queueSize)];
}

+ (BOOL) isValidURL:(NSURL*) url {
return url && [url scheme] && [url host];
}

unsigned int MAX_EVENT_SIZE = 32 * 1024; // 32 KB
unsigned int MAX_BATCH_SIZE = 500 * 1024; // 500 KB

Expand Down

0 comments on commit b4ee337

Please sign in to comment.