我们如何知道用户是否启用了推送通知?

时间:2019-07-15 03:54:01

标签: ios swift firebase push-notification

嗨,我在应用程序中使用firebase推送通知是查找用户是否启用了推送通知的任何方式吗?

任何人都请对此提供一个小主意。

2 个答案:

答案 0 :(得分:0)

您可以通过通知设置获取它

 let current = UNUserNotificationCenter.current()
  current.getNotificationSettings(completionHandler: { (settings) in
     if settings.authorizationStatus == .notDetermined {
                // Notification permission is still not requested
      } else if settings.authorizationStatus == .denied {
                // Notification permission was denied previously. User can be directed to settings to re-enable notification.

     } else if settings.authorizationStatus == .authorized {
                // Notification permission was granted previously.
     }
     })

答案 1 :(得分:0)

您可以使用以下代码来提供所有可以确定的通知状态。

UNUserNotificationCenter.current().getNotificationSettings { [weak self] notificationSettings in

        switch notificationSettings.authorizationStatus {

        case .notDetermined:
            // The user has not yet made a choice regarding whether the application may post user notifications.
            break

        case .denied:
            // The application is not authorized to post user notifications.
            break

        case .authorized:
            // The application is authorized to post user notifications.
            break

        case .provisional:  // Available from iOS 12.0
            // The application is authorized to post non-interruptive user notifications.
            break
        }
    }