I am writing an application that receives OSC messages. However, due to 10.9's App-Nap-technology the application stops reacting on these messages after leaving foreground. I want to disable AppNap for my application running on 10.9, but still be able to run on 10.8, so I tried this piece of code, but it does not show any effect.
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)]) {
[[NSProcessInfo processInfo] beginActivityWithOptions:0x00FFFFFF reason:@"receiving OSC messages"];
}
See full code on github.
The if-condition seems to work as expected and is executed on 10.9-machines. But nevertheless the app is sent to sleep. (Activity Monitor shows "App Nap: Yes" for my application).
Thanks for your help!
Power Nap is a battery-saving feature available for select apps in macOS. To turn Power Nap (App Nap) on, go to Settings > Energy Saver and select Enable Power Nap under the appropriate tab (Battery or Power Adapter).
App Nap is a related optimization, blocking inactive applications from using the CPU and other system resources. This keeps your computer's resources free, and saves battery life.
the activity need to be stored in a property. So I added this in the header-file:
@property (strong) id activity;
and then used this implementation.
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)]) {
self.activity = [[NSProcessInfo processInfo] beginActivityWithOptions:0x00FFFFFF reason:@"receiving OSC messages"];
}
Thanks to all contributors!
From your description of the problem it sounds like you might want to take a look at WWDC 2013 704 and review the section (near the end) on background continuous work. A look at the manual for the setpriority command may also be helpful. I haven't had a need to disable app nap but I think manual change of the process priority is a good approach.
2013 WWDC Video 205 (near the middle) describes some interesting aspects of app nap that can affect the outcome of whether the app is throttled. Video 209 from WWDC 2013 presents the following screenshots on Occlusion (the point where app nap engages) may be useful.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With