LoginSignup
10
5

More than 1 year has passed since last update.

【iOS15】通知許可ダイアログの「時刻指定要約で許可」の状態を取得する

Last updated at Posted at 2021-08-20

#はじめに
iOS15からNotification Summaryという機能が追加される。
それに伴い、設定アプリの通知設定画面に「時刻指定要約」という項目が追加された。
「時刻指定要約」をONにした場合、↓のように通知許可ダイアログに「時刻指定要約で許可」という項目が表示されるようになる。

時刻指定要約ON 時刻指定要約OFF
IMG_0124.PNG IMG_0125.PNG

ユーザが「時刻指定要約で許可」をタップしたかどうかで処理を分岐する場合もあるため、その判定方法を記載する。

#判定方法
UNNotificationSettingsにiOS15から追加されたscheduledDeliverySettingを使用する。

let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
    if error != nil {
        // エラー
    }
    if granted {
        // 通知許可
    }
    notificationCenter.getNotificationSettings { settings in
        switch settings.scheduledDeliverySetting {
        case .enabled:
            print("許可")
        case .disabled:
            print("許可されてない")
        case .notSupported:
            print("サポートされてない")
        }
    }
}

#注意点

  • 「時刻指定要約で許可」をタップしない限り.enabledにならず、通常の「許可」をタップした場合は.disabledになる。
  • 「時刻指定要約で許可」をタップしてもUNNotificationSettings.authorizationStatus.authorizedとなっており、処理を分ける場合は注意が必要である。

#終わりに
ユーザが誤って「時刻指定要約で許可」を押した場合、通知によっては即時に届かなくなるため、通知許可ダイアログを表示する際に何かしら配慮をした方がいいかもしれない。
また、「時刻指定要約で許可」を選択した状態でInterruption levelsActive(defaultのlevel)の通知だと常に即時通知されないようになってしまう。そのため、必要に応じてInterruption levelsTime Sensitive以上にする対応も必要である。

##参考

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5