Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable App Nap in MacOS 10.9 (Mavericks) application

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!

like image 886
danielbuechele Avatar asked Nov 07 '13 21:11

danielbuechele


People also ask

How do you change app Nap on Mac?

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).

What is Mac app Nap?

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.


2 Answers

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!

like image 60
danielbuechele Avatar answered Sep 17 '22 22:09

danielbuechele


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.

App Occlusion

Window Occlusion

Occlusion Example Hope this helps.

like image 29
Tommie C. Avatar answered Sep 18 '22 22:09

Tommie C.