From ec0057f81288343b6d080ce01adfedffed64c0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Zdvomka?= Date: Mon, 15 Mar 2021 20:33:31 +0100 Subject: [PATCH] Fix dispatching UI toast not on main thread --- Grades.xcodeproj/project.pbxproj | 36 +++++++++---------- Grades/Utilities/Log.swift | 5 +++ .../CourseDetailStudentViewController.swift | 11 ++++-- .../ViewController/LoginViewController.swift | 16 ++++++--- .../SettingsViewController.swift | 8 ++++- 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Grades.xcodeproj/project.pbxproj b/Grades.xcodeproj/project.pbxproj index e2cf158..498ba0a 100644 --- a/Grades.xcodeproj/project.pbxproj +++ b/Grades.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/Grades/Utilities/Log.swift b/Grades/Utilities/Log.swift index b3dbbc9..2aece99 100644 --- a/Grades/Utilities/Log.swift +++ b/Grades/Utilities/Log.swift @@ -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) + } } diff --git a/Grades/View/ViewController/CourseDetailStudentViewController.swift b/Grades/View/ViewController/CourseDetailStudentViewController.swift index 986ffc5..1b73999 100644 --- a/Grades/View/ViewController/CourseDetailStudentViewController.swift +++ b/Grades/View/ViewController/CourseDetailStudentViewController.swift @@ -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) diff --git a/Grades/View/ViewController/LoginViewController.swift b/Grades/View/ViewController/LoginViewController.swift index 37e8053..c605212 100644 --- a/Grades/View/ViewController/LoginViewController.swift +++ b/Grades/View/ViewController/LoginViewController.swift @@ -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) @@ -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) diff --git a/Grades/View/ViewController/SettingsViewController.swift b/Grades/View/ViewController/SettingsViewController.swift index 6c81256..79d775a 100644 --- a/Grades/View/ViewController/SettingsViewController.swift +++ b/Grades/View/ViewController/SettingsViewController.swift @@ -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)