LoginSignup
1
1

More than 1 year has passed since last update.

UNTimeIntervalNotificationTrigger.nextTriggerDate が正しい値を返さない話

Last updated at Posted at 2022-02-22

やりたいこと

UNTimeIntervalNotificationTriggerをNotificationCenterに登録したのち、あとからgetPendingNotificationRequestsを使って通知が発火する日時を知りたい。

何が変なのか

UNTimeIntervalNotificationTrigger.nextTriggerDateは、一見「次にイベントが発火する日」を返しそうだし、ドキュメントにもそう書いてあるのに、「現在時刻 + timeInterval」を常に返す。

返して欲しいもの

次にプッシュ通知が発火する日付

実際に返ってくるもの

現在時刻+timeInterval(なんの意味もない日付)

公式ドキュメント

次に発火する日が知りたかったらこのプロパティ使ってね、としっかり書いてある(2022/2/22現在)

Use this property to find out when a notification associated with this trigger will next be delivered.

ワークアラウンド

  • UNCalendarNotificationTriggerで代用できるならそうする
  • UNtimeIntervalNotificationTriggerを生成する際、UserDefaultsに起点となる日付を保存しておく(!?)

同じハマりをしてた人達

※Appleに問い合わせた結果、メンゴメンゴ、ドキュメント書いた時は楽観的だった!って返ってきた話などが書いてある。

環境

iOS 15.1.1
Xcode 13.0

1
1
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
1
1