Skip to content

Commit 0e13dcc

Browse files
authored
fix(icon): App icon logic may run in background inside unit test (#84) LP-6272
1 parent 5e63527 commit 0e13dcc

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

Example/Tests/Classes/ActionManagerTest.m

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,6 @@ - (void)test_matched_trigger
149149

150150
- (void)test_require_message_content
151151
{
152-
// This stub have to be removed when start command is successfully executed.
153-
[OHHTTPStubs stubRequestsPassingTest:
154-
^BOOL(NSURLRequest * _Nonnull request) {
155-
return [request.URL.host isEqualToString:API_HOST];
156-
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
157-
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
158-
return [OHHTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
159-
headers:@{@"Content-Type":@"application/json"}];
160-
}];
161-
162-
XCTAssertTrue([LeanplumHelper start_development_test]);
163-
164152
// Vaidate request.
165153
[LeanplumRequest validate_request:^(NSString *method, NSString *apiMethod,
166154
NSDictionary *params) {
@@ -192,18 +180,6 @@ - (void)test_notification_action
192180

193181
- (void) test_receive_notification
194182
{
195-
// This stub have to be removed when start command is successfully executed.
196-
[OHHTTPStubs stubRequestsPassingTest:
197-
^BOOL(NSURLRequest * _Nonnull request) {
198-
return [request.URL.host isEqualToString:API_HOST];
199-
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
200-
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
201-
return [OHHTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
202-
headers:@{@"Content-Type":@"application/json"}];
203-
}];
204-
205-
XCTAssertTrue([LeanplumHelper start_development_test]);
206-
207183
NSDictionary* userInfo = @{
208184
@"_lpm": @"messageId",
209185
@"_lpx": @"test_action",

Example/Tests/Classes/EventDataManagerTest.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ - (void)test_migrateRequests
9090
[[LeanplumRequest sendNowQueue] cancelAllOperations];
9191
[[LeanplumRequest sendNowQueue] waitUntilAllOperationsAreFinished];
9292

93-
NSFileManager *fileManager = [NSFileManager defaultManager];
94-
if ([fileManager fileExistsAtPath:[LPDatabase sqliteFilePath]]) {
95-
[fileManager removeItemAtPath:[LPDatabase sqliteFilePath] error:nil];
96-
}
97-
9893
[LPEventDataManager deleteEventsWithLimit:10000];
9994

10095
[[LPRequestStorage sharedStorage] popAllRequests];

Example/Tests/Classes/LeanplumTest.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ - (void) test_simple_production_start
136136
NSString* deviceModel = params[@"deviceModel"];
137137
XCTAssertTrue([deviceModel isEqualToString:@"iPhone"] ||
138138
[deviceModel isEqualToString:@"iPhone Simulator"]);
139-
XCTAssertTrue([params[@"deviceName"] isEqualToString:[[UIDevice currentDevice] name]]);
140139
XCTAssertEqualObjects(@0, params[@"includeDefaults"]);
141140
XCTAssertNotNil(params[@"locale"]);
142141
XCTAssertNotNil(params[@"timezone"]);
@@ -245,7 +244,6 @@ - (void) test_complex_production_start
245244
NSString* deviceModel = params[@"deviceModel"];
246245
XCTAssertTrue([deviceModel isEqualToString:@"iPhone"] ||
247246
[deviceModel isEqualToString:@"iPhone Simulator"]);
248-
XCTAssertTrue([params[@"deviceName"] isEqualToString:[[UIDevice currentDevice] name]]);
249247
XCTAssertEqualObjects(@0, params[@"includeDefaults"]);
250248
XCTAssertNotNil(params[@"locale"]);
251249
XCTAssertNotNil(params[@"timezone"]);

Example/Tests/Classes/Utilities/LeanplumHelper.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ + (void)clean_up {
129129
[LeanplumRequest reset];
130130
[LeanplumHelper reset_user_defaults];
131131
[[LeanplumRequest sendNowQueue] cancelAllOperations];
132+
[[LeanplumRequest sendNowQueue] waitUntilAllOperationsAreFinished];
132133
}
133134

134135
+ (dispatch_time_t)default_dispatch_time {

Leanplum-SDK/Classes/LPAppIconManager.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ + (void)uploadAppIconsOnDevMode
8282
*/
8383
+ (BOOL)supportsAlternateIcons
8484
{
85+
// Run on main thread.
86+
if (![NSThread isMainThread]) {
87+
BOOL __block outputValue = NO;
88+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
89+
dispatch_async(dispatch_get_main_queue(), ^{
90+
outputValue = [self supportsAlternateIcons];
91+
dispatch_semaphore_signal(semaphore);
92+
});
93+
dispatch_semaphore_wait(semaphore, 0.01*NSEC_PER_SEC);
94+
return outputValue;
95+
}
96+
8597
UIApplication *app = [UIApplication sharedApplication];
8698
if ([app respondsToSelector:@selector(supportsAlternateIcons)]) {
8799
return [app supportsAlternateIcons];

Leanplum-SDK/Classes/LPMessageTemplates.m

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ - (void)defineActions
322322
withArguments:@[[LPActionArg argNamed:LPMT_ARG_URL withString:LPMT_DEFAULT_URL]]
323323
withResponder:^BOOL(LPActionContext *context) {
324324
@try {
325-
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[context stringNamed:LPMT_ARG_URL]]];
325+
dispatch_async(dispatch_get_main_queue(), ^{
326+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[context stringNamed:LPMT_ARG_URL]]];
327+
});
326328
return YES;
327329
}
328330
@catch (NSException *exception) {
@@ -835,6 +837,15 @@ - (void)deferPush
835837

836838
- (BOOL)isPushEnabled
837839
{
840+
// Run on main thread.
841+
if (![NSThread isMainThread]) {
842+
BOOL __block output = NO;
843+
dispatch_sync(dispatch_get_main_queue(), ^{
844+
output = [self isPushEnabled];
845+
});
846+
return output;
847+
}
848+
838849
UIApplication *application = [UIApplication sharedApplication];
839850
BOOL enabled;
840851

@@ -1204,9 +1215,11 @@ - (void)refreshPopupContent
12041215

12051216
- (void)appStorePrompt
12061217
{
1207-
if (NSClassFromString(@"SKStoreReviewController")) {
1208-
[SKStoreReviewController requestReview];
1209-
}
1218+
dispatch_async(dispatch_get_main_queue(), ^{
1219+
if (NSClassFromString(@"SKStoreReviewController")) {
1220+
[SKStoreReviewController requestReview];
1221+
}
1222+
});
12101223
}
12111224

12121225
- (BOOL)hasAlternateIcon
@@ -1218,6 +1231,13 @@ - (BOOL)hasAlternateIcon
12181231

12191232
- (void)setAlternateIconWithFilename:(NSString *)filename
12201233
{
1234+
if (![NSThread isMainThread]) {
1235+
dispatch_sync(dispatch_get_main_queue(), ^{
1236+
[self setAlternateIconWithFilename:filename];
1237+
return;
1238+
});
1239+
}
1240+
12211241
NSString *iconName = [filename stringByReplacingOccurrencesOfString:LPMT_ICON_FILE_PREFIX
12221242
withString:@""];
12231243
iconName = [iconName stringByReplacingOccurrencesOfString:@".png" withString:@""];

0 commit comments

Comments
 (0)