فهرست منبع

Merge pull request #760 from deltachat/fix-app-delegate

fix app delegate
bjoern 5 سال پیش
والد
کامیت
3f83e4d1a5
2فایلهای تغییر یافته به همراه5 افزوده شده و 18 حذف شده
  1. 5 17
      deltachat-ios/AppDelegate.swift
  2. 0 1
      deltachat-ios/Controller/SettingsController.swift

+ 5 - 17
deltachat-ios/AppDelegate.swift

@@ -8,13 +8,6 @@ import DBDebugToolkit
 
 let logger = SwiftyBeaver.self
 
-enum ApplicationState {
-    case stopped
-    case running
-    case background
-    case backgroundFetch
-}
-
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
     private let dcContext = DcContext.shared
@@ -24,13 +17,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     private var backgroundTask: UIBackgroundTaskIdentifier = .invalid
     var reachability = Reachability()!
     var window: UIWindow?
-    var state = ApplicationState.stopped
     var appIsInForeground = false
 
     func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
+        // explicitly ignore SIGPIPE to avoid crashes, see https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/CommonPitfalls/CommonPitfalls.html
+        // setupCrashReporting() may create an additional handler, but we do not want to rely on that
+        signal(SIGPIPE, SIG_IGN)
+
         DBDebugToolkit.setup(with: []) // empty array will override default device shake trigger
+        DBDebugToolkit.setupCrashReporting()
 
-        // main()
         let console = ConsoleDestination()
         logger.addDestination(console)
         dcContext.logger = DcLogger()
@@ -154,7 +150,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     }
 
     func closeDatabase() {
-        state = .stopped
         dcContext.closeDatabase()
     }
 
@@ -209,17 +204,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     func startThreads() {
         logger.info("---- start ----")
-
-        if state == .running {
-            return
-        }
-        state = .running
-
         dcContext.maybeStartIo()
     }
 
     func stopThreads() {
-        state = .background
         dcContext.stopIo()
     }
 

+ 0 - 1
deltachat-ios/Controller/SettingsController.swift

@@ -437,7 +437,6 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
     }
 
     private func showDebugToolkit() {
-        DBDebugToolkit.setupCrashReporting() // as this might cause issues on its own, we add this handler only on opening the debugToolkit the first time
         let info: [DBCustomVariable] = dcContext.getInfo().map { kv in
             let value = kv.count > 1 ? kv[1] : ""
             return DBCustomVariable(name: kv[0], value: value)