-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix currentAppState when called before UIApplicationMain (#1248)
- Loading branch information
1 parent
0f7291b
commit 185098b
Showing
8 changed files
with
121 additions
and
8 deletions.
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,26 @@ | ||
// | ||
// UIApplicationStub.h | ||
// Bugsnag | ||
// | ||
// Created by Nick Dowell on 06/12/2021. | ||
// Copyright © 2021 Bugsnag Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface UIApplicationStub : NSObject | ||
|
||
@property (nonatomic) UIApplicationState applicationState; | ||
|
||
@end | ||
|
||
@interface XCTestCase (UIApplicationStub) | ||
|
||
- (void)setUpUIApplicationStub; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_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,38 @@ | ||
// | ||
// UIApplicationStub.m | ||
// Bugsnag | ||
// | ||
// Created by Nick Dowell on 06/12/2021. | ||
// Copyright © 2021 Bugsnag Inc. All rights reserved. | ||
// | ||
|
||
#import "UIApplicationStub.h" | ||
|
||
#import <objc/runtime.h> | ||
|
||
|
||
@implementation UIApplicationStub | ||
|
||
- (BOOL)isKindOfClass:(Class)aClass { | ||
return aClass == [UIApplication class] || [super isKindOfClass:aClass]; | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation XCTestCase (UIApplicationStub) | ||
|
||
- (void)setUpUIApplicationStub { | ||
Method method = class_getClassMethod([UIApplication class], @selector(sharedApplication)); | ||
NSParameterAssert(method != NULL); | ||
|
||
void *originalImplementation = method_setImplementation(method, imp_implementationWithBlock(^(){ | ||
return [[UIApplicationStub alloc] init]; | ||
})); | ||
|
||
[self addTeardownBlock:^{ | ||
method_setImplementation(method, originalImplementation); | ||
}]; | ||
} | ||
|
||
@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
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