diff --git a/CHANGELOG.md b/CHANGELOG.md index a8198cee..395db409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ All notable changes to this project will be documented in this file. ### Changed - Added logic to filter out the property which are not set for Application Opened event. -##Version - 1.3.0 - 2021-12-20 -### Changed +##Version - 1.3.0 - 2021-12-29 +### Additions +- Added support for additional background run time through configuration. - Added watchOS as a supported platform. + diff --git a/Examples/RudderSampleAppObjC/RudderSampleAppObjC/_AppDelegate.m b/Examples/RudderSampleAppObjC/RudderSampleAppObjC/_AppDelegate.m index 9678e783..d6a5e998 100644 --- a/Examples/RudderSampleAppObjC/RudderSampleAppObjC/_AppDelegate.m +++ b/Examples/RudderSampleAppObjC/RudderSampleAppObjC/_AppDelegate.m @@ -224,4 +224,4 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio // [FIRMessaging messaging].APNSToken = deviceToken; } -@end +@end \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index 539f0735..7a7ffeb5 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -120,7 +120,7 @@ SPEC CHECKSUMS: nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97 Protobuf: 3724efa50cb2846d7ccebc8691c574e85fd74471 - Rudder: f3f6b4a7c8d59b31a742bed98b8bdf4448ce19e1 + Rudder: 9f813b7a85c6f7f945aa876d4cfd56e7f316361c PODFILE CHECKSUM: 33b0e9f1b94a028aa8a3b4aecf718a44c9b6265e diff --git a/Sources/Classes/Public/RSConfig.h b/Sources/Classes/Public/RSConfig.h index f553bfe9..4bb749ea 100644 --- a/Sources/Classes/Public/RSConfig.h +++ b/Sources/Classes/Public/RSConfig.h @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) int configRefreshInterval; @property (nonatomic) bool trackLifecycleEvents; @property (nonatomic) bool recordScreenViews; +@property (nonatomic) bool enableBackgroundMode; @property (nonatomic, nonnull) NSString *controlPlaneUrl; @property (nonatomic, readwrite) NSMutableArray* factories; @property (nonatomic, readwrite) NSMutableArray* customFactories; diff --git a/Sources/Classes/Public/RSConfigBuilder.h b/Sources/Classes/Public/RSConfigBuilder.h index 344edb26..0faab215 100644 --- a/Sources/Classes/Public/RSConfigBuilder.h +++ b/Sources/Classes/Public/RSConfigBuilder.h @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype) withConfigRefreshInteval: (int) configRefreshInterval; - (instancetype) withTrackLifecycleEvens: (BOOL) trackLifecycleEvents; - (instancetype) withRecordScreenViews: (BOOL) recordScreenViews; +- (instancetype) withEnableBackgroundMode:(BOOL) enableBackgroundMode; - (instancetype) withConfigPlaneUrl: (NSString*) configPlaneUrl __attribute((deprecated("Use withControlPlaneUrl instead."))); - (instancetype) withControlPlaneUrl: (NSString*) controlPlaneUrl; - (instancetype) withControlPlaneURL: (NSURL*) controlPlaneURL; diff --git a/Sources/Classes/Public/RSConstants.h b/Sources/Classes/Public/RSConstants.h index 8048ca52..79159f02 100644 --- a/Sources/Classes/Public/RSConstants.h +++ b/Sources/Classes/Public/RSConstants.h @@ -29,6 +29,8 @@ extern NSString *const RSControlPlaneUrl; extern bool const RSTrackLifeCycleEvents; // whether we should record screen views automatically extern bool const RSRecordScreenViews; +// whether we should add support for background run time +extern bool const RSEnableBackgroundMode; // SDK Version extern NSString *const RS_VERSION; diff --git a/Sources/Classes/Public/RSEventRepository.h b/Sources/Classes/Public/RSEventRepository.h index 335fd39a..d0c50976 100644 --- a/Sources/Classes/Public/RSEventRepository.h +++ b/Sources/Classes/Public/RSEventRepository.h @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN NSString* authToken; NSString* anonymousIdToken; RSConfig* config; + UIBackgroundTaskIdentifier backgroundTask; RSDBPersistentManager* dbpersistenceManager; RSServerConfigManager* configManager; NSMutableDictionary* integrations; diff --git a/Sources/Classes/RSConfig.m b/Sources/Classes/RSConfig.m index ff792ea8..40a16189 100644 --- a/Sources/Classes/RSConfig.m +++ b/Sources/Classes/RSConfig.m @@ -23,6 +23,7 @@ - (instancetype)init _configRefreshInterval = RSConfigRefreshInterval; _trackLifecycleEvents = RSTrackLifeCycleEvents; _recordScreenViews = RSRecordScreenViews; + _enableBackgroundMode = RSEnableBackgroundMode; _controlPlaneUrl = RSControlPlaneUrl; _factories = [[NSMutableArray alloc] init]; _customFactories = [[NSMutableArray alloc] init]; @@ -37,8 +38,9 @@ - (instancetype)init:(NSString *) dataPlaneUrl logLevel: (int) logLevel configRefreshInterval: (int) configRefreshInteval trackLifecycleEvents: (BOOL) trackLifecycleEvents -recordScreenViews: (BOOL) recordScreenViews - controlPlaneUrl: (NSString *) controlPlaneUrl +enableBackgroundMode: (BOOL) enableBackgroundMode + recordScreenViews: (BOOL) recordScreenViews + controlPlaneUrl: (NSString *) controlPlaneUrl { self = [super init]; if (self) { @@ -51,6 +53,7 @@ - (instancetype)init:(NSString *) dataPlaneUrl _trackLifecycleEvents = trackLifecycleEvents; _recordScreenViews = recordScreenViews; _controlPlaneUrl = controlPlaneUrl; + _enableBackgroundMode = enableBackgroundMode; _factories = [[NSMutableArray alloc] init]; _customFactories = [[NSMutableArray alloc] init]; } diff --git a/Sources/Classes/RSConfigBuilder.m b/Sources/Classes/RSConfigBuilder.m index 8158f047..59914083 100644 --- a/Sources/Classes/RSConfigBuilder.m +++ b/Sources/Classes/RSConfigBuilder.m @@ -133,6 +133,14 @@ - (instancetype) withRecordScreenViews:(BOOL)recordScreenViews { return self; } +- (instancetype) withEnableBackgroundMode:(BOOL)enableBackgroundMode { + if (config == nil) { + config = [[RSConfig alloc] init]; + } + config.enableBackgroundMode = enableBackgroundMode; + return self; +} + -(instancetype)withConfigPlaneUrl:(NSString *) configPlaneUrl { if (config == nil) { config = [[RSConfig alloc] init]; diff --git a/Sources/Classes/RSConstants.m b/Sources/Classes/RSConstants.m index 30c5f212..88b7e48f 100644 --- a/Sources/Classes/RSConstants.m +++ b/Sources/Classes/RSConstants.m @@ -17,5 +17,6 @@ @implementation RSConstants NSString *const RSControlPlaneUrl = @"https://api.rudderlabs.com"; bool const RSTrackLifeCycleEvents = YES; bool const RSRecordScreenViews = NO; +bool const RSEnableBackgroundMode = NO; NSString *const RS_VERSION = @"1.3.0"; @end diff --git a/Sources/Classes/RSEventRepository.m b/Sources/Classes/RSEventRepository.m index 234f2987..3a94c38b 100644 --- a/Sources/Classes/RSEventRepository.m +++ b/Sources/Classes/RSEventRepository.m @@ -52,6 +52,12 @@ - (instancetype)init : (NSString*) _writeKey config:(RSConfig*) _config { writeKey = _writeKey; config = _config; + if(config.enableBackgroundMode) + { + [RSLogger logDebug:@"EventRepository: Enabling Background Mode"]; + backgroundTask = UIBackgroundTaskInvalid; + [self registerBackGroundTask]; + } NSData *authData = [[[NSString alloc] initWithFormat:@"%@:", _writeKey] dataUsingEncoding:NSUTF8StringEncoding]; authToken = [authData base64EncodedStringWithOptions:0]; @@ -572,12 +578,17 @@ - (void)_applicationWillEnterForeground { return; } + if(config.enableBackgroundMode) { + [self registerBackGroundTask]; + } + [[RSClient sharedInstance] track:@"Application Opened" properties:@{ @"from_background" : @YES }]; } - (void)_applicationDidEnterBackground { + if ([self getOptStatus]) { return; } @@ -595,5 +606,19 @@ - (void) __prepareScreenRecorder { #endif } +- (void) registerBackGroundTask { + if(backgroundTask != UIBackgroundTaskInvalid) { + [self endBackGroundTask]; + } + [RSLogger logDebug:@"EventRepository: registerBackGroundTask: Registering for Background Mode"]; + backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + [self endBackGroundTask]; + }]; +} + +- (void) endBackGroundTask { + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + backgroundTask = UIBackgroundTaskInvalid; +} @end