How can I register for Thermal Change Notifications using NSProcessInfoThermalStateDidChangeNotification ?

Hello,

I am trying to add some logging for Thermal State Changes in my iOS app. I have followed the instructions outlined in this documentation, however I am not recieving the notifications for thermal state change.

I know I have set the code up correctly because I have switched NSProcessInfoThermalStateDidChangeNotification out for NSProcessInfoPowerStateDidChange and my code runs as expected.

I have tried
  • enabling various thermal device conditions via Xcode

  • heating up the actual device until I received the tempurature notification then allowing the device to cool back down while using my app

I am testing on iPhone XR - iOS 13.6.1
Accepted Answer
Does your code even read the thermalState property, that is, outside of your notification handler? Looking at the code it’s this initial read that sets up the notification mechanism.

[And yeah, that’s super non-obvious, so if this is the problem then we’ll definitely be filing a bug against the docs!]

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
That was my problem! Just adding this one line of code before calling addObserver fixed my issue:
Code Block
[[NSProcessInfo processInfo] thermalState];

Thanks so much!

That was my problem!

Cool. Thanks for letting my know. And I filed a bug against the NSProcessInfoThermalStateDidChangeNotification docs (r. 69254275).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Just wasted a good day on this. Disappointing the docs are *still* not fixed.
How can I register for Thermal Change Notifications using NSProcessInfoThermalStateDidChangeNotification ?
 
 
Q