This repository has been archived by the owner on Feb 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 265
Fix/access applicationstate on main thread #484
Closed
ElektrojungeAtWork
wants to merge
13
commits into
master
from
fix/access-applicationstate-on-main-thread
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
856d264
Access applicationstate from mainthread
a76b336
use dispatch_sync instead of dispatch_async
6b9c28f
Fix deadlock. =)
13d3989
Fix typo in BITChannel from previous commit that would cause persistD…
14a52c2
Add HockeyHelper+Application to get applicationstate and use it every…
f7c7b7f
add linebreak and remove unnecessary ? YES : NO
1ff86a5
Merge remote-tracking branch 'Public/master' into fix/access-applicat…
189634b
Remove check for application != nil as the new application state has …
9a80720
Update OCMock and OCHamcrest
7bc46ed
Update to OCMock 3.4.1
65e0f75
Add runtime search path for OCMock
2d0d42b
Fix unit tests for Channel by using a completionhandler block.
ddd8f95
add missing change to BITMetricsManager from local stash
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#import "BITHockeyHelper+Application.h" | ||
|
||
/* | ||
* Workaround for exporting symbols from category object files. | ||
*/ | ||
NSString *BITHockeyHelperApplicationCategory; | ||
|
||
@implementation BITHockeyHelper (Application) | ||
|
||
/** | ||
* @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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't work. #486 fixes it. |
||
[NSString stringWithFormat:@"%@", BITHockeyHelperApplicationCategory]; | ||
} | ||
|
||
+ (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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -197,7 +198,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) ? YES : NO; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
if (application && applicationIsInBackground) { | ||
[self.channel createBackgroundTask:application withWaitingGroup:group]; | ||
} | ||
} | ||
|
@@ -222,7 +224,7 @@ - (void)trackEventWithName:(nonnull NSString *)eventName properties:(nullable NS | |
|
||
// If the app is running in the background. | ||
UIApplication *application = [UIApplication sharedApplication]; | ||
if (application && application.applicationState == UIApplicationStateBackground) { | ||
BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground) ? YES : NO; if (application && applicationIsInBackground) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
[self.channel createBackgroundTask:application withWaitingGroup:group]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just
applicationIsInBackground
, no need to checkapplication
here