Skip to content

Commit

Permalink
Added precautions for start state
Browse files Browse the repository at this point in the history
  • Loading branch information
erkanyildiz committed Mar 10, 2018
1 parent dfa508c commit 919b018
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Countly.m
Expand Up @@ -57,6 +57,11 @@ - (instancetype)init

- (void)startWithConfig:(CountlyConfig *)config
{
if (CountlyCommon.sharedInstance.hasStarted)
return;

CountlyCommon.sharedInstance.hasStarted = YES;

CountlyCommon.sharedInstance.enableDebug = config.enableDebug;

NSAssert(config.appKey && ![config.appKey isEqualToString:@"YOUR_APP_KEY"], @"[CountlyAssert] App key in Countly configuration is not set!");
Expand Down Expand Up @@ -137,6 +142,9 @@ - (void)startWithConfig:(CountlyConfig *)config

- (void)setNewDeviceID:(NSString *)deviceID onServer:(BOOL)onServer
{
if (!CountlyCommon.sharedInstance.hasStarted)
return;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

Expand Down Expand Up @@ -218,6 +226,9 @@ - (void)onTimer:(NSTimer *)timer

- (void)suspend
{
if (!CountlyCommon.sharedInstance.hasStarted)
return;

if (isSuspended)
return;

Expand All @@ -237,6 +248,9 @@ - (void)suspend

- (void)resume
{
if (!CountlyCommon.sharedInstance.hasStarted)
return;

#if TARGET_OS_WATCH
//NOTE: skip first time to prevent double begin session because of applicationDidBecomeActive call on launch of watchOS apps
static BOOL isFirstCall = YES;
Expand Down
3 changes: 3 additions & 0 deletions CountlyAPM.m
Expand Up @@ -14,6 +14,9 @@ @implementation CountlyAPM

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyAPM* s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
1 change: 1 addition & 0 deletions CountlyCommon.h
Expand Up @@ -58,6 +58,7 @@ extern NSString* const kCountlySDKName;

@interface CountlyCommon : NSObject

@property (nonatomic) BOOL hasStarted;
@property (nonatomic) BOOL enableDebug;
@property (nonatomic) BOOL enableAppleWatch;
@property (nonatomic) BOOL enableAttribution;
Expand Down
3 changes: 3 additions & 0 deletions CountlyConnectionManager.m
Expand Up @@ -58,6 +58,9 @@ @implementation CountlyConnectionManager : NSObject

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyConnectionManager *s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
3 changes: 3 additions & 0 deletions CountlyCrashReporter.m
Expand Up @@ -52,6 +52,9 @@ @implementation CountlyCrashReporter

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyCrashReporter *s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
3 changes: 3 additions & 0 deletions CountlyPersistency.m
Expand Up @@ -23,6 +23,9 @@ @implementation CountlyPersistency

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyPersistency* s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
3 changes: 3 additions & 0 deletions CountlyPushNotifications.m
Expand Up @@ -24,6 +24,9 @@ @implementation CountlyPushNotifications

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyPushNotifications* s_sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
3 changes: 3 additions & 0 deletions CountlyStarRating.m
Expand Up @@ -32,6 +32,9 @@ @implementation CountlyStarRating

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyStarRating* s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down
3 changes: 3 additions & 0 deletions CountlyUserDetails.m
Expand Up @@ -169,6 +169,9 @@ - (void)pull:(NSString *)key values:(NSArray *)value

- (void)save
{
if (!CountlyCommon.sharedInstance.hasStarted)
return;

NSString* userDetails = [CountlyUserDetails.sharedInstance serializedUserDetails];
if (userDetails)
[CountlyConnectionManager.sharedInstance sendUserDetails:userDetails];
Expand Down
3 changes: 3 additions & 0 deletions CountlyViewTracking.m
Expand Up @@ -23,6 +23,9 @@ @implementation CountlyViewTracking

+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;

static CountlyViewTracking* s_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
Expand Down

0 comments on commit 919b018

Please sign in to comment.