Переглянути джерело

use .provisional notifications that allows the user to opt in when there is actually a notification; also makes room for a customized dialog

B. Petersen 3 роки тому
батько
коміт
ae16c08cc8
1 змінених файлів з 8 додано та 6 видалено
  1. 8 6
      deltachat-ios/AppDelegate.swift

+ 8 - 6
deltachat-ios/AppDelegate.swift

@@ -247,19 +247,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         notifyToken = nil
 
         // register for showing notifications
-        //
-        // note: the alert-dialog cannot be customized, however, since iOS 12,
-        // it can be avoided completely by using `.provisional`,
-        // https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications
+        var opt: UNAuthorizationOptions = [.alert, .sound, .badge]
+        if #available(iOS 12.0, *) {
+            // .provisional notifications delay the consent of the user to the moment the first notification is shown,
+            // as a drawback, until that moment, notifications are less visible.
+            opt = [.provisional, .alert, .sound, .badge]
+        }
         UNUserNotificationCenter.current()
-          .requestAuthorization(options: [.alert, .sound, .badge]) { [weak self] granted, _ in
+          .requestAuthorization(options: opt) { [weak self] granted, error in
             if granted {
                 // we are allowed to show notifications:
                 // register for receiving remote notifications
                 logger.info("Notifications: Permission granted: \(granted)")
                 self?.maybeRegisterForRemoteNotifications()
             } else {
-                logger.info("Notifications: Permission not granted.")
+                logger.info("Notifications: Permission not granted: \(String(describing: error))")
             }
         }
     }