Skip to content

Commit 4dec51c

Browse files
onatonguyenhuy
authored andcommitted
Fix ASDKgram example #trivial (TextureGroup#700)
- Fix an insta-crash that's caused by Webservice.load method to call its completion block off the main thread. - Fix incorrect http status code check. - Bump the deployment target to get the project compiling.
1 parent fff5aae commit 4dec51c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

examples_extra/ASDKgram-Swift/ASDKgram-Swift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
429429
GCC_WARN_UNUSED_FUNCTION = YES;
430430
GCC_WARN_UNUSED_VARIABLE = YES;
431-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
431+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
432432
MTL_ENABLE_DEBUG_INFO = YES;
433433
ONLY_ACTIVE_ARCH = YES;
434434
SDKROOT = iphoneos;
@@ -478,7 +478,7 @@
478478
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
479479
GCC_WARN_UNUSED_FUNCTION = YES;
480480
GCC_WARN_UNUSED_VARIABLE = YES;
481-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
481+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
482482
MTL_ENABLE_DEBUG_INFO = NO;
483483
SDKROOT = iphoneos;
484484
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

examples_extra/ASDKgram-Swift/ASDKgram-Swift/Webservice.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ final class WebService {
2525
URLSession.shared.dataTask(with: resource.url) { data, response, error in
2626
// Check for errors in responses.
2727
let result = self.checkForNetworkErrors(data, response, error)
28-
29-
switch result {
30-
case .success(let data):
31-
completion(resource.parse(data))
32-
case .failure(let error):
33-
completion(.failure(error))
28+
DispatchQueue.main.async {
29+
switch result {
30+
case .success(let data):
31+
completion(resource.parse(data))
32+
case .failure(let error):
33+
completion(.failure(error))
34+
}
3435
}
3536
}.resume()
3637
}
@@ -49,7 +50,7 @@ extension WebService {
4950
}
5051
}
5152

52-
if let response = response as? HTTPURLResponse, response.statusCode >= 200 && response.statusCode <= 299 {
53+
if let response = response as? HTTPURLResponse, response.statusCode <= 200 && response.statusCode >= 299 {
5354
return .failure((.invalidStatusCode("Request returned status code other than 2xx \(response)")))
5455
}
5556

0 commit comments

Comments
 (0)