Help us understand the problem. What is going on with this article?

【iOS14】UNUserNotificationCenterでSwitch must be exhaustiveのwarning対応

Xcode12(GM)でビルドするとSwitch must be exhaustiveのwarningが👀
実装を確認すると、通知許可ステータスを確認するコードで吐き出されている様子

        UNUserNotificationCenter.current().getNotificationSettings { settings in
            switch settings.authorizationStatus {
            case .authorized, .provisional:
                print("許可")
            case .denied:
                print("拒否")
            case .notDetermined:
                print("許可求む")
            @unknown default:
                fatalError()
            }

UNAuthorizationStatusのリファレンスを覗くとiOS14から新たに
.ephemeral
が追加されていました。
https://developer.apple.com/documentation/usernotifications/unauthorizationstatus

この子は
The application is temporarily authorized to post notifications. Only available to app clips.
つまり、iOS14から実装可能なApp Clipsにおいて、一時的に通知の許可を取ることができ、そのステータスということです。

App Clipsを実装している場合の実装はこちらの公式リファレンスを参考に
https://developer.apple.com/documentation/app_clips/enabling_notifications_in_app_clips

let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in {
    if settings.authorizationStatus == .ephemeral {

        // The user didn't disable notifications in the app clip card.
        // Add code for scheduling or receiving notifications here.
        return
    }
}

などを追加します。

App Clipsを実装していない場合は、通らない想定なので

        UNUserNotificationCenter.current().getNotificationSettings { settings in
            switch settings.authorizationStatus {
            case .authorized, .provisional:
                print("許可")
            case .denied:
                print("拒否")
            case .notDetermined:
                print("許可求む")
            case .ephemeral:
                fatalError()// or assertionFailure()
            @unknown default:
                fatalError()
            }

でwarning回避できます。
リファレンスにbetaと書かれているし、fatalError利用したくない方は念の為
assertionFailureで、取得失敗の扱いで良いかと思います🙋‍♂️

ご参考までに🐣🌱

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした