Skip to content

Commit

Permalink
Fix dispatching UI toast not on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jstorm31 committed Mar 15, 2021
1 parent da0b3fc commit ec0057f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
36 changes: 18 additions & 18 deletions Grades.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,8 @@
buildSettings = {
APP_VERSION = 0.1.3;
CODE_SIGN_ENTITLEMENTS = GradesNotificationExtension/GradesNotificationExtension.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Debug;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = LK4H72N842;
Expand All @@ -1632,7 +1632,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades.NotificationExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Grades Notification Extension - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand All @@ -1644,8 +1644,8 @@
buildSettings = {
APP_VERSION = 0.1.3;
CODE_SIGN_ENTITLEMENTS = GradesNotificationExtension/GradesNotificationExtension.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Test;
DEVELOPMENT_TEAM = LK4H72N842;
ENABLE_BITCODE = NO;
Expand All @@ -1663,7 +1663,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades.NotificationExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Grades Notification Extension - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand All @@ -1675,8 +1675,8 @@
buildSettings = {
APP_VERSION = 0.1.3;
CODE_SIGN_ENTITLEMENTS = GradesNotificationExtension/GradesNotificationExtension.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Release;
DEVELOPMENT_TEAM = LK4H72N842;
ENABLE_BITCODE = NO;
Expand All @@ -1694,7 +1694,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades.NotificationExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Grades Notification Extension - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand Down Expand Up @@ -1831,8 +1831,8 @@
APP_VERSION = 0.1.3;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Grades/Grades.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Debug;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = LK4H72N842;
Expand All @@ -1856,7 +1856,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades;
PRODUCT_NAME = Grades;
PROVISIONING_PROFILE_SPECIFIER = "Grades - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_WORKSPACE = YES;
Expand All @@ -1871,8 +1871,8 @@
APP_VERSION = 0.1.3;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Grades/Grades.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Release;
DEVELOPMENT_TEAM = LK4H72N842;
ENABLE_BITCODE = NO;
Expand All @@ -1895,7 +1895,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades;
PRODUCT_NAME = Grades;
PROVISIONING_PROFILE_SPECIFIER = "Grades - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_WORKSPACE = YES;
Expand Down Expand Up @@ -2024,8 +2024,8 @@
APP_VERSION = 0.1.3;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Grades/Grades.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CONFIG_ENVIRONMENT = Test;
DEVELOPMENT_TEAM = LK4H72N842;
ENABLE_BITCODE = NO;
Expand All @@ -2048,7 +2048,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = cz.cvut.fit.grades;
PRODUCT_NAME = Grades;
PROVISIONING_PROFILE_SPECIFIER = "Grades - AppStore";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_WORKSPACE = YES;
Expand Down
5 changes: 5 additions & 0 deletions Grades/Utilities/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ class Log {
print("⛔️ \(message)")
SentrySDK.capture(message: message)
}

static func report(_ error: Error) {
print("⛔️ \(error) \(error.localizedDescription)")
SentrySDK.capture(error: error)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ class CourseDetailStudentViewController: BaseTableViewController, BindableType {

viewModel.error.asObserver()
.subscribe(onNext: { [weak self] error in
self?.navigationController?.view
.makeCustomToast(error?.localizedDescription, type: .danger, position: .center)
if let error = error {
Log.report(error)
}

DispatchQueue.main.async {
if let view = self?.navigationController?.view {
view.makeCustomToast(error?.localizedDescription, type: .danger, position: .center)
}
}
})
.disposed(by: bag)

Expand Down
16 changes: 12 additions & 4 deletions Grades/View/ViewController/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ class LoginViewController: BaseViewController, BindableType, ConfirmationModalPr
viewModel.authenticateWithRefresToken()
.subscribeOn(MainScheduler.instance)
.subscribe(onError: { [weak self] error in
self?.view.makeCustomToast(error.localizedDescription, type: .danger)
Log.report(error)

DispatchQueue.main.async {
if let view = self?.view {
view.makeCustomToast(error.localizedDescription, type: .danger)
}
}
})
.disposed(by: bag)

Expand Down Expand Up @@ -121,10 +127,12 @@ class LoginViewController: BaseViewController, BindableType, ConfirmationModalPr
viewModel.authenticate(viewController: self)
.subscribeOn(MainScheduler.instance)
.subscribe(onError: { [weak self] error in
Log.error(error.localizedDescription)
Log.report(error)

if let view = self?.view {
view.makeCustomToast(error.localizedDescription, type: .danger)
DispatchQueue.main.async {
if let view = self?.view {
view.makeCustomToast(error.localizedDescription, type: .danger)
}
}
})
.disposed(by: bag)
Expand Down
8 changes: 7 additions & 1 deletion Grades/View/ViewController/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ final class SettingsViewController: BaseTableViewController,
viewModel.error
.subscribeOn(MainScheduler.instance)
.subscribe(onError: { [weak self] error in
self?.view.makeCustomToast(error.localizedDescription, type: .danger)
Log.report(error)

DispatchQueue.main.async {
if let view = self?.view {
view.makeCustomToast(error.localizedDescription, type: .danger)
}
}
})
.disposed(by: bag)

Expand Down

0 comments on commit ec0057f

Please sign in to comment.