Application Nap ?

Discussion in 'Mac Programming' started by DennisBlah, Mar 4, 2015.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hi all,

    I have made an application that is scanning for bluetooth beacons.
    Once one is found is is with X meters, it will trigger an script to check authentication of this device.
    (This is security related application, to prevent unauthorised devices to leave the building)

    Now the thing is, sometimes it looks like the app is sleeping, and when I move the mouse it will start working straight away.
    Even when the display is not sleeping yet.

    Anyone have any advice for me ?
    Thanks!
     
  2. TheBSDGuy macrumors 6502

    Joined:
    Jan 24, 2012
    #2
    Welcome to the world of App Nap. App Nap is a "feature" implemented that's supposed to save energy. What it does is put applications to sleep, without warning, without the user knowing about it. It's probably the worst implementation of an idea I've ever seen. If you go to the Apple App Store and read some of the comments about Yosemite, a lot of them state stuff like "it took 24 hours to download." My guess is that App Nap has put their application to sleep while downloading. Apple should have put a warning up before allowing an application to enter App Nap and give people options to either allow it to occur or disable it for a given application. They didn't, and it confuses a lot of people.

    Here are your options:

    1. Tell users to open up the "info" panel for it and check the "disable App Nap" option.

    2. Hard code it into your installation to ignore app nap. See the developer documentation for that.

    3. Disable App Nap system wide. You'll need to do a Google or Bing search on it but it's easily done via command line.

    I don't know that I think that it's a bad idea, but the implementation is horrible. Been there, done that.

    Good luck and don't worry. I suspect you can fix it.
     
  3. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    Yeah there is nothing that can't be fixed with a pop-up window. :rolleyes: Seriously though, an application that does active work, such as downloading a file shouldn't go to sleep. I'm not sure what is different with App Nap and previously inactive applications which always reported as sleeping in top for example. In that state they use up no CPU resources and can even be paged to a VM backing store if there is a need I believe.
     
  4. Ritsuka macrumors 6502a

    Joined:
    Sep 3, 2006
    #4
    Check the api to tell the system you are running an background operation. It's the application duty to tell the system it doesn't want to be suspended.
     
  5. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    Odd, should we also use yields to get CPU time? If an application has been registered with launchd to run in the background the system should already know it's a background process and when it's suppose to run.
     
  6. Ritsuka macrumors 6502a

    Joined:
    Sep 3, 2006
    #6
    We don't know if the app in question is a daemon or a gui app…
     
  7. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #7
    Sure, the comment is just me expressing a WTF sentiment in delegating kernel micro management to user land developers.
     
  8. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #8
    I'm gonna try option 3. Since option 1 is not an option.
    Not because I don't want the users to do it, but because they can't.
    For some reason the whole tickbox for 'Prevent App Nap' does not show up for my app executable.
    Code:
    defaults write NSGlobalDomain NSAppSleepDisabled -bool YES
    Just gonna throw it in the app to run it as root ;-)

    I couldn't find anything clear enough for option 2.
    Any advice ? Or link would be appriciated :)

    It's an gui application, the user is able to choose an minimum distance for starting the authentication of the device to be taken out of the building and by who. It's a kind of middle-ware for a FileMaker database.
    Wireless authentication <3
     
  9. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #10

Share This Page