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

Commit 377ecab

Browse files
author
Benjamin Scholtysik (Reimold)
authored
Merge pull request #443 from bmourat/fix/get-resource-value-async
Calling getResourceValue asynchronously
2 parents 3258b89 + 31cd9be commit 377ecab

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

Classes/BITHockeyHelper.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,18 @@ void bit_fixBackupAttributeForURL(NSURL *directoryURL) {
159159
}
160160

161161
if (directoryURL) {
162-
NSError *getResourceError = nil;
163-
NSNumber *appSupportDirExcludedValue;
164-
165-
if ([directoryURL getResourceValue:&appSupportDirExcludedValue forKey:NSURLIsExcludedFromBackupKey error:&getResourceError] && appSupportDirExcludedValue) {
166-
NSError *setResourceError = nil;
167-
[directoryURL setResourceValue:@NO forKey:NSURLIsExcludedFromBackupKey error:&setResourceError];
168-
}
162+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
163+
NSError *getResourceError = nil;
164+
NSNumber *appSupportDirExcludedValue;
165+
if ([directoryURL getResourceValue:&appSupportDirExcludedValue forKey:NSURLIsExcludedFromBackupKey error:&getResourceError] && appSupportDirExcludedValue) {
166+
NSError *setResourceError = nil;
167+
if(![directoryURL setResourceValue:@NO forKey:NSURLIsExcludedFromBackupKey error:&setResourceError]) {
168+
BITHockeyLogError(@"ERROR: Error while setting resource value: %@", setResourceError.localizedDescription);
169+
}
170+
} else {
171+
BITHockeyLogError(@"ERROR: Error while retrieving resource value: %@", getResourceError.localizedDescription);
172+
}
173+
});
169174
}
170175
}
171176

Support/HockeySDKTests/BITHockeyHelperTests.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,20 @@ - (NSURL *)createBackupExcludedTestDirectoryForURL{
307307
}
308308

309309
- (BOOL)excludeAttributeIsSetForURL:(NSURL *)directoryURL {
310-
311-
NSError *getResourceError = nil;
312-
NSNumber *appSupportDirExcludedValue;
313-
if ([directoryURL getResourceValue:&appSupportDirExcludedValue forKey:NSURLIsExcludedFromBackupKey error:&getResourceError] && appSupportDirExcludedValue) {
314-
if ([appSupportDirExcludedValue isEqualToValue:@YES]) {
315-
return YES;
310+
__block BOOL result = NO;
311+
XCTestExpectation *expectation = [self expectationWithDescription:@"wait"];
312+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
313+
NSError *getResourceError = nil;
314+
NSNumber *appSupportDirExcludedValue;
315+
if ([directoryURL getResourceValue:&appSupportDirExcludedValue forKey:NSURLIsExcludedFromBackupKey error:&getResourceError] && appSupportDirExcludedValue) {
316+
if ([appSupportDirExcludedValue isEqualToValue:@YES]) {
317+
result = YES;
318+
}
316319
}
317-
}
318-
return NO;
320+
[expectation fulfill];
321+
});
322+
[self waitForExpectationsWithTimeout:5 handler:nil];
323+
return result;
319324
}
320325

321326
@end

0 commit comments

Comments
 (0)