@@ -69,64 +69,66 @@ + (BNCApplication*) createCurrentApplication {
6969 return application;
7070}
7171
72- + (NSDate *) currentBuildDate {
72+ + (NSDate *) currentBuildDate {
7373 NSURL *appURL = nil ;
7474 NSURL *bundleURL = [NSBundle mainBundle ].bundleURL ;
7575 NSDictionary *info = [NSBundle mainBundle ].infoDictionary ;
76- NSString *appName = info[(__bridge NSString *)kCFBundleExecutableKey ];
76+ NSString *appName = info[(__bridge NSString *)kCFBundleExecutableKey ];
7777 if (appName.length > 0 && bundleURL) {
7878 appURL = [bundleURL URLByAppendingPathComponent: appName];
7979 } else {
8080 NSString *path = [[NSProcessInfo processInfo ].arguments firstObject ];
81- if (path) appURL = [NSURL fileURLWithPath: path];
81+ if (path) {
82+ appURL = [NSURL fileURLWithPath: path];
83+ }
8284 }
83- if (appURL == nil )
85+ if (appURL == nil ) {
86+ [[BranchLogger shared ] logWarning: @" Failed to get build date, app path is nil" error: nil ];
8487 return nil ;
88+ }
8589
8690 NSError *error = nil ;
8791 NSFileManager *fileManager = [NSFileManager defaultManager ];
8892 NSDictionary *attributes = [fileManager attributesOfItemAtPath: appURL.path error: &error];
8993 if (error) {
90- [[BranchLogger shared ] logError: [ NSString stringWithFormat: @" Can't get build date: %@ . " , error] error: error];
94+ [[BranchLogger shared ] logWarning: @" Failed to get build date" error: error];
9195 return nil ;
9296 }
93- NSDate * buildDate = [attributes fileCreationDate ];
97+ NSDate *buildDate = [attributes fileCreationDate ];
9498 if (buildDate == nil || [buildDate timeIntervalSince1970 ] <= 0.0 ) {
95- [[BranchLogger shared ] logError : [NSString stringWithFormat: @" Invalid build date: %@ . " , buildDate] error: nil ];
99+ [[BranchLogger shared ] logWarning : [NSString stringWithFormat: @" Invalid build date: %@ " , buildDate] error: nil ];
96100 }
97101 return buildDate;
98102}
99103
100- + (NSDate *) firstInstallBuildDate {
104+ + (NSDate *) firstInstallBuildDate {
101105 NSError *error = nil ;
102- NSDate *firstBuildDate =
103- [BNCKeyChain retrieveDateForService: kBranchKeychainService
104- key: kBranchKeychainFirstBuildKey
105- error: &error];
106- if (firstBuildDate)
106+ NSDate *firstBuildDate = [BNCKeyChain retrieveDateForService: kBranchKeychainService key: kBranchKeychainFirstBuildKey error: &error];
107+ if (firstBuildDate) {
107108 return firstBuildDate;
108-
109+ }
110+
109111 firstBuildDate = [self currentBuildDate ];
110- error = [BNCKeyChain storeDate: firstBuildDate
111- forService: kBranchKeychainService
112- key: kBranchKeychainFirstBuildKey
113- cloudAccessGroup: nil ];
114- if (error) [[BranchLogger shared ] logError: [NSString stringWithFormat: @" Keychain store: %@ ." , error] error: error];
115-
112+ error = [BNCKeyChain storeDate: firstBuildDate forService: kBranchKeychainService key: kBranchKeychainFirstBuildKey cloudAccessGroup: nil ];
113+ if (error) {
114+ [[BranchLogger shared ] logWarning: @" Error while saving build date" error: error];
115+ }
116116 return firstBuildDate;
117117}
118118
119- + (NSDate *) currentInstallDate {
119+ + (NSDate *)currentInstallDate {
120120 NSDate *installDate = [NSDate date ];
121121
122122 #if !TARGET_OS_TV
123123 // tvOS always returns a creation date of Unix epoch 0 on device
124124 installDate = [self creationDateForLibraryDirectory ];
125- #endif
126-
127125 if (installDate == nil || [installDate timeIntervalSince1970 ] <= 0.0 ) {
128- [[BranchLogger shared ] logWarning: [ NSString stringWithFormat: @" Invalid install date, using [NSDate date]. " ] error: nil ];
126+ [[BranchLogger shared ] logWarning: @" Invalid install date, using [NSDate date]" error: nil ];
129127 }
128+ #else
129+ [[BranchLogger shared ] logWarning: @" File system creation date not supported on tvOS, using [NSDate date]" error: nil ];
130+ #endif
131+
130132 return installDate;
131133}
132134
@@ -136,13 +138,13 @@ + (NSDate *)creationDateForLibraryDirectory {
136138 NSURL *directoryURL = [[fileManager URLsForDirectory: NSLibraryDirectory inDomains: NSUserDomainMask] firstObject ];
137139 NSDictionary *attributes = [fileManager attributesOfItemAtPath: directoryURL.path error: &error];
138140 if (error) {
139- [[BranchLogger shared ] logError: [ NSString stringWithFormat: @" Can't get creation date for Library directory: %@ " , error] error: error];
140- return nil ;
141+ [[BranchLogger shared ] logWarning: @" Failed to get creation date for Library directory" error: error];
142+ return nil ;
141143 }
142144 return [attributes fileCreationDate ];
143145}
144146
145- + (NSDate *) firstInstallDate {
147+ + (NSDate *) firstInstallDate {
146148 // check keychain for stored install date, on iOS this is lost on app deletion.
147149 NSError *error = nil ;
148150 NSDate * firstInstallDate = [BNCKeyChain retrieveDateForService: kBranchKeychainService key: kBranchKeychainFirstInstalldKey error: &error];
@@ -156,7 +158,7 @@ + (NSDate*) firstInstallDate {
156158 // save filesystem time to keychain
157159 error = [BNCKeyChain storeDate: firstInstallDate forService: kBranchKeychainService key: kBranchKeychainFirstInstalldKey cloudAccessGroup: nil ];
158160 if (error) {
159- [[BranchLogger shared ] logError: [ NSString stringWithFormat: @" Keychain store: %@ . " , error] error: error];
161+ [[BranchLogger shared ] logWarning: @" Error while saving install date " error: error];
160162 }
161163 return firstInstallDate;
162164}
0 commit comments