Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit b6c0d55

Browse files
author
Benjamin Scholtysik (Reimold)
authored
Merge pull request #485 from bitstadium/release/5.1.0
Release/5.1.0
2 parents 880181b + cd7d697 commit b6c0d55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+598
-163
lines changed

Classes/BITAuthenticator.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#import "BITAuthenticationViewController.h"
3737
#import "BITHockeyAppClient.h"
3838
#import "BITHockeyHelper.h"
39+
#import "BITHockeyHelper+Application.h"
3940
#import "BITHockeyBaseManagerPrivate.h"
4041

4142
#include <sys/stat.h>
@@ -105,12 +106,13 @@ - (void)authenticateInstallation {
105106
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(authenticateInstallation) object:nil];
106107
[self performSelector:@selector(authenticateInstallation) withObject:nil afterDelay:0.1];
107108
} else {
108-
switch ([[UIApplication sharedApplication] applicationState]) {
109-
case UIApplicationStateActive:
109+
switch ([BITHockeyHelper applicationState]) {
110+
case BITApplicationStateActive:
110111
[self authenticate];
111112
break;
112-
case UIApplicationStateBackground:
113-
case UIApplicationStateInactive:
113+
case BITApplicationStateBackground:
114+
case BITApplicationStateInactive:
115+
case BITApplicationStateUnknown:
114116
// do nothing, wait for active state
115117
break;
116118
}
@@ -743,7 +745,7 @@ + (void)email:(NSString *__autoreleasing *)email andIUID:(NSString *__autoreleas
743745
#pragma mark - Private helpers
744746

745747
- (void)alertOnFailureStoringTokenInKeychain {
746-
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
748+
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
747749
return;
748750
}
749751

Classes/BITChannel.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import "BITHockeyManager.h"
77
#import "BITChannelPrivate.h"
88
#import "BITHockeyHelper.h"
9+
#import "BITHockeyHelper+Application.h"
910
#import "BITTelemetryContext.h"
1011
#import "BITTelemetryData.h"
1112
#import "BITEnvelope.h"
@@ -257,11 +258,17 @@ - (void)resetQueue {
257258
#pragma mark - Adding to queue
258259

259260
- (void)enqueueTelemetryItem:(BITTelemetryData *)item {
260-
261+
[self enqueueTelemetryItem:item completionHandler:nil];
262+
}
263+
264+
- (void)enqueueTelemetryItem:(BITTelemetryData *)item completionHandler:(nullable void (^)(void))completionHandler {
261265
if (!item) {
262266

263267
// Item is nil: Do not enqueue item and abort operation.
264268
BITHockeyLogWarning(@"WARNING: TelemetryItem was nil.");
269+
if(completionHandler) {
270+
completionHandler();
271+
}
265272
return;
266273
}
267274

@@ -278,16 +285,22 @@ - (void)enqueueTelemetryItem:(BITTelemetryData *)item {
278285
if (![strongSelf timerIsRunning]) {
279286
[strongSelf startTimer];
280287
}
288+
289+
if(completionHandler) {
290+
completionHandler();
291+
}
292+
281293
return;
282294
}
283295

284296
// Enqueue item.
285297
@synchronized(self) {
286298
NSDictionary *dict = [strongSelf dictionaryForTelemetryData:item];
287299
[strongSelf appendDictionaryToEventBuffer:dict];
288-
UIApplication *application = [UIApplication sharedApplication];
300+
// If the app is running in the background.
301+
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground);
289302
if (strongSelf.dataItemCount >= strongSelf.maxBatchSize ||
290-
(application && application.applicationState == UIApplicationStateBackground)) {
303+
(applicationIsInBackground)) {
291304

292305
// Case 2: Max batch count has been reached or the app is running in the background, so write queue to disk and delete all items.
293306
[strongSelf persistDataItemQueue:&BITTelemetryEventBuffer];
@@ -298,6 +311,10 @@ - (void)enqueueTelemetryItem:(BITTelemetryData *)item {
298311
[strongSelf startTimer];
299312
}
300313
}
314+
315+
if(completionHandler) {
316+
completionHandler();
317+
}
301318
}
302319
});
303320
}

Classes/BITChannelPrivate.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ void bit_resetEventBuffer(char *__nonnull*__nonnull eventBuffer);
109109
*/
110110
- (BOOL)isQueueBusy;
111111

112+
/**
113+
* Enqueue a telemetry item. This is for testing purposes where we actually use the completion handler.
114+
*
115+
* @param completionHandler The completion handler that will be called after enqueuing a BITTelemetryData object.
116+
*
117+
* @discussion intended for testing purposes.
118+
*/
119+
- (void)enqueueTelemetryItem:(BITTelemetryData *)item completionHandler:(nullable void (^)(void))completionHandler;
120+
112121
@end
113122

114123
NS_ASSUME_NONNULL_END

Classes/BITCrashManager.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#import "HockeySDKPrivate.h"
3939
#import "BITHockeyHelper.h"
40+
#import "BITHockeyHelper+Application.h"
4041
#import "BITHockeyAppClient.h"
4142

4243
#import "BITCrashManager.h"
@@ -1052,8 +1053,7 @@ - (void)triggerDelayedProcessing {
10521053
*/
10531054
- (void)invokeDelayedProcessing {
10541055
#if !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions)
1055-
if (!bit_isRunningInAppExtension() &&
1056-
[[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
1056+
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
10571057
return;
10581058
}
10591059
#endif
@@ -1277,7 +1277,7 @@ - (void)startManager {
12771277
}
12781278

12791279
#if !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions)
1280-
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
1280+
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
12811281
[self appEnteredForeground];
12821282
}
12831283
#else

Classes/BITFeedbackListViewController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
716716
#pragma mark - ListViewCellDelegate
717717

718718
- (void)listCell:(id) __unused cell didSelectAttachment:(BITFeedbackMessageAttachment *)attachment {
719+
if (!self.cachedPreviewItems){
720+
[self refreshPreviewItems];
721+
}
722+
719723
QLPreviewController *previewController = [[QLPreviewController alloc] init];
720724
previewController.dataSource = self;
721725

@@ -739,10 +743,6 @@ - (void)refreshPreviewItems {
739743
}
740744

741745
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *) __unused controller {
742-
if (!self.cachedPreviewItems){
743-
[self refreshPreviewItems];
744-
}
745-
746746
return self.cachedPreviewItems.count;
747747
}
748748

Classes/BITFeedbackManager.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#import "HockeySDKNullability.h"
4444
#import "BITHockeyHelper.h"
45+
#import "BITHockeyHelper+Application.h"
4546
#import "BITHockeyAppClient.h"
4647

4748
#define kBITFeedbackUserDataAsked @"HockeyFeedbackUserDataAsked"
@@ -131,7 +132,7 @@ - (void)didBecomeActiveActions {
131132
- (void)didEnterBackgroundActions {
132133
self.didEnterBackgroundState = NO;
133134

134-
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
135+
if ([BITHockeyHelper applicationState] == BITApplicationStateBackground) {
135136
self.didEnterBackgroundState = YES;
136137
}
137138
}
@@ -270,15 +271,16 @@ - (void)startManager {
270271
[self isiOS10PhotoPolicySet];
271272

272273
// we are already delayed, so the notification already came in and this won't invoked twice
273-
switch ([[UIApplication sharedApplication] applicationState]) {
274-
case UIApplicationStateActive:
274+
switch ([BITHockeyHelper applicationState]) {
275+
case BITApplicationStateActive:
275276
// we did startup, so yes we are coming from background
276277
self.didEnterBackgroundState = YES;
277278

278279
[self didBecomeActiveActions];
279280
break;
280-
case UIApplicationStateBackground:
281-
case UIApplicationStateInactive:
281+
case BITApplicationStateBackground:
282+
case BITApplicationStateInactive:
283+
case BITApplicationStateUnknown:
282284
// do nothing, wait for active state
283285
break;
284286
}

Classes/BITHockeyHelper+Application.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#import <Foundation/Foundation.h>
2+
#import <UIKit/UIKit.h>
3+
4+
#import "BITHockeyHelper.h"
5+
/*
6+
* Workaround for exporting symbols from category object files.
7+
*/
8+
extern NSString *BITHockeyHelperApplicationCategory;
9+
10+
/**
11+
* App states
12+
*/
13+
typedef NS_ENUM(NSInteger, BITApplicationState) {
14+
15+
/**
16+
* Application is active.
17+
*/
18+
BITApplicationStateActive = UIApplicationStateActive,
19+
20+
/**
21+
* Application is inactive.
22+
*/
23+
BITApplicationStateInactive = UIApplicationStateInactive,
24+
25+
/**
26+
* Application is in background.
27+
*/
28+
BITApplicationStateBackground = UIApplicationStateBackground,
29+
30+
/**
31+
* Application state can't be determined.
32+
*/
33+
BITApplicationStateUnknown
34+
};
35+
36+
@interface BITHockeyHelper (Application)
37+
38+
/**
39+
* Get current application state.
40+
*
41+
* @return Current state of the application or BITApplicationStateUnknown while the state can't be determined.
42+
*
43+
* @discussion The application state may not be available everywhere. Application extensions doesn't have it for instance,
44+
* in that case the BITApplicationStateUnknown value is returned.
45+
*/
46+
+ (BITApplicationState)applicationState;
47+
48+
@end

Classes/BITHockeyHelper+Application.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#import "BITHockeyHelper+Application.h"
2+
3+
/*
4+
* Workaround for exporting symbols from category object files.
5+
*/
6+
NSString *BITHockeyHelperApplicationCategory;
7+
8+
@implementation BITHockeyHelper (Application)
9+
10+
+ (BITApplicationState)applicationState {
11+
12+
// App extensions must not access sharedApplication.
13+
if (!bit_isRunningInAppExtension()) {
14+
15+
__block BITApplicationState state;
16+
dispatch_block_t block = ^{
17+
state = (BITApplicationState)[[self class] sharedAppState];
18+
};
19+
20+
if ([NSThread isMainThread]) {
21+
block();
22+
} else {
23+
dispatch_sync(dispatch_get_main_queue(), block);
24+
}
25+
26+
return state;
27+
}
28+
return BITApplicationStateUnknown;
29+
}
30+
31+
+ (UIApplication *)sharedApplication {
32+
33+
// Compute selector at runtime for more discretion.
34+
SEL sharedAppSel = NSSelectorFromString(@"sharedApplication");
35+
return ((UIApplication * (*)(id, SEL))[[UIApplication class] methodForSelector:sharedAppSel])([UIApplication class],
36+
sharedAppSel);
37+
}
38+
39+
+ (UIApplicationState)sharedAppState {
40+
return [[[[self class] sharedApplication] valueForKey:@"applicationState"] longValue];
41+
}
42+
43+
@end

Classes/BITHockeyHelper.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828

2929

30-
#import "BITHockeyHelper.h"
30+
#import "BITHockeyHelper+Application.h"
3131
#import "BITKeychainUtils.h"
3232
#import "HockeySDK.h"
3333
#import "HockeySDKPrivate.h"
@@ -43,6 +43,15 @@
4343

4444
@implementation BITHockeyHelper
4545

46+
/**
47+
* @discussion
48+
* Workaround for exporting symbols from category object files.
49+
* See article https://medium.com/ios-os-x-development/categories-in-static-libraries-78e41f8ddb96#.aedfl1kl0
50+
*/
51+
__attribute__((used)) static void importCategories() {
52+
[NSString stringWithFormat:@"%@", BITHockeyHelperApplicationCategory];
53+
}
54+
4655
+ (BOOL)isURLSessionSupported {
4756
id nsurlsessionClass = NSClassFromString(@"NSURLSessionUploadTask");
4857
BOOL isUrlSessionSupported = (nsurlsessionClass && !bit_isRunningInAppExtension());

Classes/BITMetricsManager.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import "BITTelemetryContext.h"
77
#import "BITMetricsManagerPrivate.h"
88
#import "BITHockeyHelper.h"
9+
#import "BITHockeyHelper+Application.h"
910
#import "HockeySDKPrivate.h"
1011
#import "BITChannelPrivate.h"
1112
#import "BITEventData.h"
@@ -199,7 +200,8 @@ - (void)trackEventWithName:(nonnull NSString *)eventName {
199200

200201
// If the app is running in the background.
201202
UIApplication *application = [UIApplication sharedApplication];
202-
if (application && application.applicationState == UIApplicationStateBackground) {
203+
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground);
204+
if (applicationIsInBackground) {
203205
[self.channel createBackgroundTaskWhileDataIsSending:application withWaitingGroup:group];
204206
}
205207
}
@@ -228,7 +230,8 @@ - (void)trackEventWithName:(nonnull NSString *)eventName
228230

229231
// If the app is running in the background.
230232
UIApplication *application = [UIApplication sharedApplication];
231-
if (application && application.applicationState == UIApplicationStateBackground) {
233+
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground);
234+
if (applicationIsInBackground) {
232235
[self.channel createBackgroundTaskWhileDataIsSending:application withWaitingGroup:group];
233236
}
234237
}

Classes/BITStoreUpdateManager.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#import "HockeySDKPrivate.h"
3636
#import "BITHockeyHelper.h"
37+
#import "BITHockeyHelper+Application.h"
3738

3839
#import "BITHockeyBaseManagerPrivate.h"
3940
#import "BITStoreUpdateManagerPrivate.h"
@@ -416,12 +417,13 @@ - (void)startManager {
416417
[self registerObservers];
417418

418419
// we are already delayed, so the notification already came in and this won't invoked twice
419-
switch ([[UIApplication sharedApplication] applicationState]) {
420-
case UIApplicationStateActive:
420+
switch ([BITHockeyHelper applicationState]) {
421+
case BITApplicationStateActive:
421422
[self didBecomeActiveActions];
422423
break;
423-
case UIApplicationStateBackground:
424-
case UIApplicationStateInactive:
424+
case BITApplicationStateBackground:
425+
case BITApplicationStateInactive:
426+
case BITApplicationStateUnknown:
425427
// do nothing, wait for active state
426428
break;
427429
}

Classes/BITUpdateManager.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#import "HockeySDKPrivate.h"
3838
#import "BITHockeyHelper.h"
39+
#import "BITHockeyHelper+Application.h"
3940

4041
#import "BITHockeyBaseManagerPrivate.h"
4142
#import "BITUpdateManagerPrivate.h"
@@ -141,7 +142,7 @@ - (void)didBecomeActiveActions {
141142
- (void)didEnterBackgroundActions {
142143
self.didEnterBackgroundState = NO;
143144

144-
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
145+
if ([BITHockeyHelper applicationState] == BITApplicationStateBackground) {
145146
self.didEnterBackgroundState = YES;
146147
}
147148
}
@@ -867,7 +868,7 @@ - (void)startManager {
867868
[self checkExpiryDateReached];
868869
if (![self expiryDateReached]) {
869870
if ([self isCheckForUpdateOnLaunch] && [self shouldCheckForUpdates]) {
870-
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) return;
871+
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) return;
871872

872873
[self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0];
873874
}

0 commit comments

Comments
 (0)