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

Commit

Permalink
Merge pull request #485 from bitstadium/release/5.1.0
Browse files Browse the repository at this point in the history
Release/5.1.0
  • Loading branch information
Benjamin Scholtysik (Reimold) authored Dec 12, 2017
2 parents 880181b + cd7d697 commit b6c0d55
Show file tree
Hide file tree
Showing 51 changed files with 598 additions and 163 deletions.
12 changes: 7 additions & 5 deletions Classes/BITAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#import "BITAuthenticationViewController.h"
#import "BITHockeyAppClient.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "BITHockeyBaseManagerPrivate.h"

#include <sys/stat.h>
Expand Down Expand Up @@ -105,12 +106,13 @@ - (void)authenticateInstallation {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(authenticateInstallation) object:nil];
[self performSelector:@selector(authenticateInstallation) withObject:nil afterDelay:0.1];
} else {
switch ([[UIApplication sharedApplication] applicationState]) {
case UIApplicationStateActive:
switch ([BITHockeyHelper applicationState]) {
case BITApplicationStateActive:
[self authenticate];
break;
case UIApplicationStateBackground:
case UIApplicationStateInactive:
case BITApplicationStateBackground:
case BITApplicationStateInactive:
case BITApplicationStateUnknown:
// do nothing, wait for active state
break;
}
Expand Down Expand Up @@ -743,7 +745,7 @@ + (void)email:(NSString *__autoreleasing *)email andIUID:(NSString *__autoreleas
#pragma mark - Private helpers

- (void)alertOnFailureStoringTokenInKeychain {
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
return;
}

Expand Down
23 changes: 20 additions & 3 deletions Classes/BITChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import "BITHockeyManager.h"
#import "BITChannelPrivate.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "BITTelemetryContext.h"
#import "BITTelemetryData.h"
#import "BITEnvelope.h"
Expand Down Expand Up @@ -257,11 +258,17 @@ - (void)resetQueue {
#pragma mark - Adding to queue

- (void)enqueueTelemetryItem:(BITTelemetryData *)item {

[self enqueueTelemetryItem:item completionHandler:nil];
}

- (void)enqueueTelemetryItem:(BITTelemetryData *)item completionHandler:(nullable void (^)(void))completionHandler {
if (!item) {

// Item is nil: Do not enqueue item and abort operation.
BITHockeyLogWarning(@"WARNING: TelemetryItem was nil.");
if(completionHandler) {
completionHandler();
}
return;
}

Expand All @@ -278,16 +285,22 @@ - (void)enqueueTelemetryItem:(BITTelemetryData *)item {
if (![strongSelf timerIsRunning]) {
[strongSelf startTimer];
}

if(completionHandler) {
completionHandler();
}

return;
}

// Enqueue item.
@synchronized(self) {
NSDictionary *dict = [strongSelf dictionaryForTelemetryData:item];
[strongSelf appendDictionaryToEventBuffer:dict];
UIApplication *application = [UIApplication sharedApplication];
// If the app is running in the background.
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground);
if (strongSelf.dataItemCount >= strongSelf.maxBatchSize ||
(application && application.applicationState == UIApplicationStateBackground)) {
(applicationIsInBackground)) {

// 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.
[strongSelf persistDataItemQueue:&BITTelemetryEventBuffer];
Expand All @@ -298,6 +311,10 @@ - (void)enqueueTelemetryItem:(BITTelemetryData *)item {
[strongSelf startTimer];
}
}

if(completionHandler) {
completionHandler();
}
}
});
}
Expand Down
9 changes: 9 additions & 0 deletions Classes/BITChannelPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ void bit_resetEventBuffer(char *__nonnull*__nonnull eventBuffer);
*/
- (BOOL)isQueueBusy;

/**
* Enqueue a telemetry item. This is for testing purposes where we actually use the completion handler.
*
* @param completionHandler The completion handler that will be called after enqueuing a BITTelemetryData object.
*
* @discussion intended for testing purposes.
*/
- (void)enqueueTelemetryItem:(BITTelemetryData *)item completionHandler:(nullable void (^)(void))completionHandler;

@end

NS_ASSUME_NONNULL_END
Expand Down
6 changes: 3 additions & 3 deletions Classes/BITCrashManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#import "HockeySDKPrivate.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "BITHockeyAppClient.h"

#import "BITCrashManager.h"
Expand Down Expand Up @@ -1052,8 +1053,7 @@ - (void)triggerDelayedProcessing {
*/
- (void)invokeDelayedProcessing {
#if !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions)
if (!bit_isRunningInAppExtension() &&
[[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
return;
}
#endif
Expand Down Expand Up @@ -1277,7 +1277,7 @@ - (void)startManager {
}

#if !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions)
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) {
[self appEnteredForeground];
}
#else
Expand Down
8 changes: 4 additions & 4 deletions Classes/BITFeedbackListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
#pragma mark - ListViewCellDelegate

- (void)listCell:(id) __unused cell didSelectAttachment:(BITFeedbackMessageAttachment *)attachment {
if (!self.cachedPreviewItems){
[self refreshPreviewItems];
}

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;

Expand All @@ -739,10 +743,6 @@ - (void)refreshPreviewItems {
}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *) __unused controller {
if (!self.cachedPreviewItems){
[self refreshPreviewItems];
}

return self.cachedPreviewItems.count;
}

Expand Down
12 changes: 7 additions & 5 deletions Classes/BITFeedbackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#import "HockeySDKNullability.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "BITHockeyAppClient.h"

#define kBITFeedbackUserDataAsked @"HockeyFeedbackUserDataAsked"
Expand Down Expand Up @@ -131,7 +132,7 @@ - (void)didBecomeActiveActions {
- (void)didEnterBackgroundActions {
self.didEnterBackgroundState = NO;

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
if ([BITHockeyHelper applicationState] == BITApplicationStateBackground) {
self.didEnterBackgroundState = YES;
}
}
Expand Down Expand Up @@ -270,15 +271,16 @@ - (void)startManager {
[self isiOS10PhotoPolicySet];

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

[self didBecomeActiveActions];
break;
case UIApplicationStateBackground:
case UIApplicationStateInactive:
case BITApplicationStateBackground:
case BITApplicationStateInactive:
case BITApplicationStateUnknown:
// do nothing, wait for active state
break;
}
Expand Down
48 changes: 48 additions & 0 deletions Classes/BITHockeyHelper+Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "BITHockeyHelper.h"
/*
* Workaround for exporting symbols from category object files.
*/
extern NSString *BITHockeyHelperApplicationCategory;

/**
* App states
*/
typedef NS_ENUM(NSInteger, BITApplicationState) {

/**
* Application is active.
*/
BITApplicationStateActive = UIApplicationStateActive,

/**
* Application is inactive.
*/
BITApplicationStateInactive = UIApplicationStateInactive,

/**
* Application is in background.
*/
BITApplicationStateBackground = UIApplicationStateBackground,

/**
* Application state can't be determined.
*/
BITApplicationStateUnknown
};

@interface BITHockeyHelper (Application)

/**
* Get current application state.
*
* @return Current state of the application or BITApplicationStateUnknown while the state can't be determined.
*
* @discussion The application state may not be available everywhere. Application extensions doesn't have it for instance,
* in that case the BITApplicationStateUnknown value is returned.
*/
+ (BITApplicationState)applicationState;

@end
43 changes: 43 additions & 0 deletions Classes/BITHockeyHelper+Application.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#import "BITHockeyHelper+Application.h"

/*
* Workaround for exporting symbols from category object files.
*/
NSString *BITHockeyHelperApplicationCategory;

@implementation BITHockeyHelper (Application)

+ (BITApplicationState)applicationState {

// App extensions must not access sharedApplication.
if (!bit_isRunningInAppExtension()) {

__block BITApplicationState state;
dispatch_block_t block = ^{
state = (BITApplicationState)[[self class] sharedAppState];
};

if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), block);
}

return state;
}
return BITApplicationStateUnknown;
}

+ (UIApplication *)sharedApplication {

// Compute selector at runtime for more discretion.
SEL sharedAppSel = NSSelectorFromString(@"sharedApplication");
return ((UIApplication * (*)(id, SEL))[[UIApplication class] methodForSelector:sharedAppSel])([UIApplication class],
sharedAppSel);
}

+ (UIApplicationState)sharedAppState {
return [[[[self class] sharedApplication] valueForKey:@"applicationState"] longValue];
}

@end
11 changes: 10 additions & 1 deletion Classes/BITHockeyHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/


#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "BITKeychainUtils.h"
#import "HockeySDK.h"
#import "HockeySDKPrivate.h"
Expand All @@ -43,6 +43,15 @@

@implementation BITHockeyHelper

/**
* @discussion
* Workaround for exporting symbols from category object files.
* See article https://medium.com/ios-os-x-development/categories-in-static-libraries-78e41f8ddb96#.aedfl1kl0
*/
__attribute__((used)) static void importCategories() {
[NSString stringWithFormat:@"%@", BITHockeyHelperApplicationCategory];
}

+ (BOOL)isURLSessionSupported {
id nsurlsessionClass = NSClassFromString(@"NSURLSessionUploadTask");
BOOL isUrlSessionSupported = (nsurlsessionClass && !bit_isRunningInAppExtension());
Expand Down
7 changes: 5 additions & 2 deletions Classes/BITMetricsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import "BITTelemetryContext.h"
#import "BITMetricsManagerPrivate.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"
#import "HockeySDKPrivate.h"
#import "BITChannelPrivate.h"
#import "BITEventData.h"
Expand Down Expand Up @@ -199,7 +200,8 @@ - (void)trackEventWithName:(nonnull NSString *)eventName {

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

// If the app is running in the background.
UIApplication *application = [UIApplication sharedApplication];
if (application && application.applicationState == UIApplicationStateBackground) {
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground);
if (applicationIsInBackground) {
[self.channel createBackgroundTaskWhileDataIsSending:application withWaitingGroup:group];
}
}
Expand Down
10 changes: 6 additions & 4 deletions Classes/BITStoreUpdateManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#import "HockeySDKPrivate.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"

#import "BITHockeyBaseManagerPrivate.h"
#import "BITStoreUpdateManagerPrivate.h"
Expand Down Expand Up @@ -416,12 +417,13 @@ - (void)startManager {
[self registerObservers];

// we are already delayed, so the notification already came in and this won't invoked twice
switch ([[UIApplication sharedApplication] applicationState]) {
case UIApplicationStateActive:
switch ([BITHockeyHelper applicationState]) {
case BITApplicationStateActive:
[self didBecomeActiveActions];
break;
case UIApplicationStateBackground:
case UIApplicationStateInactive:
case BITApplicationStateBackground:
case BITApplicationStateInactive:
case BITApplicationStateUnknown:
// do nothing, wait for active state
break;
}
Expand Down
5 changes: 3 additions & 2 deletions Classes/BITUpdateManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#import "HockeySDKPrivate.h"
#import "BITHockeyHelper.h"
#import "BITHockeyHelper+Application.h"

#import "BITHockeyBaseManagerPrivate.h"
#import "BITUpdateManagerPrivate.h"
Expand Down Expand Up @@ -141,7 +142,7 @@ - (void)didBecomeActiveActions {
- (void)didEnterBackgroundActions {
self.didEnterBackgroundState = NO;

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
if ([BITHockeyHelper applicationState] == BITApplicationStateBackground) {
self.didEnterBackgroundState = YES;
}
}
Expand Down Expand Up @@ -867,7 +868,7 @@ - (void)startManager {
[self checkExpiryDateReached];
if (![self expiryDateReached]) {
if ([self isCheckForUpdateOnLaunch] && [self shouldCheckForUpdates]) {
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) return;
if ([BITHockeyHelper applicationState] != BITApplicationStateActive) return;

[self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0];
}
Expand Down
Loading

0 comments on commit b6c0d55

Please sign in to comment.