From b1f0f7084973cabc3c055a11764057e66a2413de Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 21 Sep 2012 19:42:18 +0200 Subject: [PATCH] Localytics SDK update because of startup issue. --- Localytics/LocalyticsDatabase.h | 0 Localytics/LocalyticsDatabase.m | 0 Localytics/LocalyticsSession.h | 8 +-- Localytics/LocalyticsSession.m | 97 +++++++++++++++++--------------- Localytics/LocalyticsUploader.h | 0 Localytics/LocalyticsUploader.m | 0 Localytics/WebserviceConstants.h | 0 7 files changed, 56 insertions(+), 49 deletions(-) mode change 100644 => 100755 Localytics/LocalyticsDatabase.h mode change 100644 => 100755 Localytics/LocalyticsDatabase.m mode change 100644 => 100755 Localytics/LocalyticsSession.h mode change 100644 => 100755 Localytics/LocalyticsSession.m mode change 100644 => 100755 Localytics/LocalyticsUploader.h mode change 100644 => 100755 Localytics/LocalyticsUploader.m mode change 100644 => 100755 Localytics/WebserviceConstants.h diff --git a/Localytics/LocalyticsDatabase.h b/Localytics/LocalyticsDatabase.h old mode 100644 new mode 100755 diff --git a/Localytics/LocalyticsDatabase.m b/Localytics/LocalyticsDatabase.m old mode 100644 new mode 100755 diff --git a/Localytics/LocalyticsSession.h b/Localytics/LocalyticsSession.h old mode 100644 new mode 100755 index 6b18ca91..9f2f6859 --- a/Localytics/LocalyticsSession.h +++ b/Localytics/LocalyticsSession.h @@ -154,10 +154,10 @@ closed and the time of closing is recorded. When the app returns to the foreground, the session is resumed. If the time since closing is greater than BACKGROUND_SESSION_TIMEOUT, (15 seconds by default) a new session is created, and uploading is triggered. Otherwise, the previous session - is reopened. It is possible to use the return value to determine whether or not a session was resumed. - This may be useful to some customers looking to do conditional instrumentation at the close of a session. - It is perfectly reasonable to ignore the return value. - @result YES if the sesion was resumed NO if it wasn't (suggesting a new session was created instead).*/ + is reopened. + @return Returns whether the session was resumed or a new session was started. If the user has opted + out of analytics then the return from this method is undefined. +*/ - (BOOL)resume; /*! diff --git a/Localytics/LocalyticsSession.m b/Localytics/LocalyticsSession.m old mode 100644 new mode 100755 index c0599b38..ad660a7c --- a/Localytics/LocalyticsSession.m +++ b/Localytics/LocalyticsSession.m @@ -22,7 +22,7 @@ #pragma mark Constants #define PREFERENCES_KEY @"_localytics_install_id" // The randomly generated ID for each install of the app -#define CLIENT_VERSION @"iOS_2.12" // The version of this library +#define CLIENT_VERSION @"iOS_2.14" // The version of this library #define LOCALYTICS_DIR @".localytics" // The directory in which the Localytics database is stored #define IFT_ETHER 0x6 // Ethernet CSMACD #define PATH_TO_APT @"/private/var/lib/apt/" @@ -200,48 +200,54 @@ CLLocationCoordinate2D lastDeviceLocation = {0}; }); } - - (BOOL)resume { - __block BOOL resumed = NO; - dispatch_sync(_queue,^{ - @try { - // Do nothing if session is already open - if(self.isSessionOpen == YES) { - resumed = YES; - return; - } - - if([self ll_isOptedIn] == false) { - [self logMessage:@"Can't resume session because user is opted out."]; - resumed = NO; - return; - } - - // conditions for resuming previous session - if(self.sessionHasBeenOpen && - (!self.sessionCloseTime || - [self.sessionCloseTime timeIntervalSinceNow]*-1 <= self.backgroundSessionTimeout)) { - // Note that we allow the session to be resumed even if the database size exceeds the - // maximum. This is because we don't want to create incomplete sessions. If the DB was large - // enough that the previous session could not be opened, there will be nothing to resume. But - // if this session caused it to go over it is better to let it complete and stop the next one - // from being created. - [self logMessage:@"Resume called - Resuming previous session."]; - [self reopenPreviousSession]; - - resumed = YES; - } else { - // otherwise open new session and upload - [self logMessage:@"Resume called - Opening a new session."]; - [self ll_open]; - - resumed = NO; - } - self.sessionCloseTime = nil; - } @catch (NSException *e) {} - }); - return resumed; + + // Do nothing if session is already open + if(self.isSessionOpen == YES) + return YES; + + BOOL ret = NO; + // conditions for resuming previous session + if(self.sessionHasBeenOpen && + (!self.sessionCloseTime || + [self.sessionCloseTime timeIntervalSinceNow]*-1 <= self.backgroundSessionTimeout)) { + // Note that we allow the session to be resumed even if the database size exceeds the + // maximum. This is because we don't want to create incomplete sessions. If the DB was large + // enough that the previous session could not be opened, there will be nothing to resume. But + // if this session caused it to go over it is better to let it complete and stop the next one + // from being created. + ret = YES; + dispatch_async(_queue, ^{ + @try { + if([self ll_isOptedIn] == false) { + [self logMessage:@"Can't resume session because user is opted out."]; + } else { + [self logMessage:@"Resume called - Resuming previous session."]; + [self reopenPreviousSession]; + } + } + @catch (NSException * e) {} + }); + + } else { + ret = NO; + dispatch_async(_queue, ^{ + @try { + if([self ll_isOptedIn] == false) { + [self logMessage:@"Can't resume session because user is opted out."]; + } else { + // otherwise open new session and upload + [self logMessage:@"Resume called - Opening a new session."]; + [self ll_open]; + } + } + @catch (NSException * e) {} + }); + + } + self.sessionCloseTime = nil; + return ret; } - (void)close { @@ -1120,10 +1126,11 @@ CLLocationCoordinate2D lastDeviceLocation = {0}; */ - (NSString *)advertisingIdentifier { NSString *adId = nil; - SEL adidSelector = NSSelectorFromString(@"identifierForAdvertising"); - if ([[UIDevice currentDevice] respondsToSelector:adidSelector]) { - adId = [[[UIDevice currentDevice] performSelector:adidSelector] performSelector:NSSelectorFromString(@"UUIDString")]; - } + Class advertisingClass = NSClassFromString(@"ASIdentifierManager"); + if (advertisingClass) { + SEL adidSelector = NSSelectorFromString(@"advertisingIdentifier"); + adId = [[[advertisingClass performSelector:NSSelectorFromString(@"sharedManager")] performSelector:adidSelector] performSelector:NSSelectorFromString(@"UUIDString")]; + } return adId; } diff --git a/Localytics/LocalyticsUploader.h b/Localytics/LocalyticsUploader.h old mode 100644 new mode 100755 diff --git a/Localytics/LocalyticsUploader.m b/Localytics/LocalyticsUploader.m old mode 100644 new mode 100755 diff --git a/Localytics/WebserviceConstants.h b/Localytics/WebserviceConstants.h old mode 100644 new mode 100755