浏览代码

use wording registerForShowingNotifications(), call only if configured, remove duplicate code

B. Petersen 4 年之前
父节点
当前提交
58a5a3afa5
共有 2 个文件被更改,包括 6 次插入11 次删除
  1. 5 10
      deltachat-ios/AppDelegate.swift
  2. 1 1
      deltachat-ios/Controller/AccountSetupController.swift

+ 5 - 10
deltachat-ios/AppDelegate.swift

@@ -70,9 +70,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Check if launched from notification
         let notificationOption = launchOptions?[.remoteNotification]
         print(notificationOption)
-        
-        registerForPushNotifications()
 
+        if dcContext.isConfigured() {
+            registerForShowingNotifications()
+        }
 
         return true
     }
@@ -266,19 +267,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     // MARK: - PushNotifications
 
-    func registerForPushNotifications() {
+    func registerForShowingNotifications() {
         print("register push")
         UNUserNotificationCenter.current().delegate = self
 
-        UNUserNotificationCenter.current()
-            .requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
-                logger.info("permission granted: \(granted)")
-                guard granted else { return }
-                self.getNotificationSettings()
-            }
         UNUserNotificationCenter.current()
           .requestAuthorization(options: [.alert, .sound, .badge]) {
-            [weak self] granted, error in
+            [weak self] granted, _ in
               
             print("Permission granted: \(granted)")
             guard granted else { return }

+ 1 - 1
deltachat-ios/Controller/AccountSetupController.swift

@@ -776,7 +776,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     private func handleLoginSuccess() {
         // used when login hud successfully went through
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
-        appDelegate.registerForPushNotifications()
+        appDelegate.registerForShowingNotifications()
         initSelectionCells();
         if let onLoginSuccess = self.onLoginSuccess {
             onLoginSuccess()