Prevent App Nap and 2014R3v1 ?

Hi All,

When I compile my application on 2014R3v1 - I’m not seeing the ‘Prevent App Nap’ option under Get Info. I have another app which I last compiled under 2014r1 and this option is there.

I’ve just downloaded 2014R2v1 and with a copy of my App, compiled and the option is there under Get Info - so I’m pretty sure this is a bug in 2014R3 (and also v1). There is however a warning on opening that I may loose something if I save using an older version.

I’ve written a network Client / Server application using 2014R3 and everything is working nicely - except when the app goes to the background and then:

  1. The Server doesn’t respond or is really slow.
  2. The Client starts missing messages from the server.

At the moment, the server is a standard app with a couple of windows. I’ve designed it to run as a console app and once settled down, I’ll make this into a console app and run as a service, but for these early stages it was easier to write with an interface.
In the mean time, I’ve sorted the server out by using terminal to prevent App Nap for all applications and restarted the server. This appears to have resolved the server issue.

For the client however - this isn’t quite so realistic. So, what am I risking by going back to 2014R2 with my app? Initial tests, I can’t find anything broken and it does give me the ‘Prevent App Nap’ option in the finders Get Info.

thanks

Kent.

you call beginActivity method of NSProcessInfoMBS class to start activity:
https://www.monkeybreadsoftware.net/class-nsprocessinfombs.shtml

Thanks, I had found that thread and have executed

The problem seems to be that 2014R3 isn’t making the ‘Prevent App Nap’ option available via the ‘Get Info’ dialog - and is going to sleep (having a Nap) as a result.

When I compile via 2014R2 - then the ‘Prevent App Nap’ option is available via Get Info and I can stop it going to sleep (manually and programatically)

I suspect this is a bug in 2014R3 - I updated another app I wrote in 2014R1 - which did have the option under Get Info - but when compiled under 2014R3 - it didn’t.

Kent.

I don’t think this is a bug, none of Apple’s app have the checkbox (at least in 10.10 Yosemite), if it still shows up for older applications, it’s probably there for apps which are built against an older version of AppKit.

Don’t forget, Apple expect you the developer to be using their tools and adhere to their guidelines! So as far as they’re concerned you shouldn’t need this option as your application should be built adhering to their guidelines.

Just to understand you correctly, it’s the client application that has an issue when it goes into App Nap, the server side is fine?

If so, how is the client communicating with the server?

Apps built with newer SDK (like newer Xojo versions) is expected to use proper API to declare when it’s busy.
See NSProcessInfo functions.

I am trying to build a generic start/stop of AppNapping but am getting errors:

  • the constructor of this class is protected
    ** this is not an array, but you are using it as one

Christian, what am I doing wrong? I thought I was using the format from your web site (https://www.monkeybreadsoftware.net/class-nsprocessinfombs.shtml)

[code]Sub doAllowAppNap(AllowAppNap As Boolean = True)
'set app to not sleep when running
'forum.xojo.com/10898-mavericks-is-putting-my-app-to-sleep/0
'forum.xojo.com/18925-prevent-app-nap-and-2014r3v1/0#p158822

Dim tempNSProcessInfoActivityMBS As New NSProcessInfoActivityMBS '*

if AllowAppNap then
tempNSProcessInfoActivityMBS(NSProcessInfoMBS.NSActivityUserInitiatedAllowingIdleSystemSleep, “Backup running”) '**
else
tempNSProcessInfoActivityMBS(NSProcessInfoMBS.NSActivityIdleSystemSleepDisabled, “Backup not running”)
end if

End Sub
[/code]

well, first you don’t need the new on NSProcessInfoActivityMBS declaration.
Next you should put NSProcessInfoActivityMBS property in a window, so it stays alive.
The plugin calls endActivity in the destructor if you don’t call it.

Thank you. I’ll give it a try.

maybe like this:

[code] dim Activity as NSProcessInfoActivityMBS // property in your window, control, thread, app
dim AllowAppNap as boolean // allow or not?

dim ProcessInfo as NSProcessInfoMBS = NSProcessInfoMBS.processInfo
if AllowAppNap then
Activity = nil
else
// disable sleep to let us make something…
Activity = ProcessInfo.beginActivity(NSProcessInfoMBS.NSActivityBackground, “Backup running”)
end if[/code]

Okay, so it appears what you are saying is that 2014R3 is compiling the app against the new Apple standards - hence the ‘Allow App Nap’ option is no longer showing - and this is intended behaviour.

What I was noticing, is that my ‘Server’ app was ‘Napping’ and when this was happening - my ‘Client’ apps were not able to connect to the ‘Server’ and/or it was really slow to respond to requests (if already connected).

I’ve compiled the ‘Server’ app using 2014R2 and turned on the ‘Prevent App Nap’ option - as a result of doing this, we haven’t noticed the connection issues and/or slowness.

I’m also now compiling the ‘Client’ app using 2014R2 and also enabled the ‘Prevent App Nap’ option - but today I’ll re-download 2014R3, recompile and see if I notice any issues as a result.

The thing I noticed - was when the app went into Nap mode - the TCP communication appeared to stop and it lost messages that were sent to it in the mean time.
However - I need to go back and retest this once I’ve recompiled with 2014R3 - now that I have a better understand of what’s going on.

thanks
Kent.

https://forum.xojo.com/10898-mavericks-is-putting-my-app-to-sleep/0

Kent, my advice on this matter is address App Nap. It may require some research and digging on your behalf, but I would take the time now (unless you really don’t have time) to resolve this correctly. Using an older version of Xojo to avoid the problem works today, but there is no guarantee that when 10.10.3 comes out it no longer works.

I know it’s frustrating when something like this happens and you’re not sure how to deal with it, it happens to me all the time.

If your server application is a console application, I seem to recall you mentioned that it is. It shouldn’t enter App Nap.

Hi Norman,

Thanks - I had seen this link. I’m still confused why when I compile with 2014R2 I get the “Prevent App Nap” option in the Get Info dialog, but it’s gone when compiling with 2014R3. Was this an intended change by Xojo or not ?

Hi Sam,

I agree. I’ve gone back to using 2014R3 today. My Service was a interface app - but I had developed it with the intention of it being a console application - which as I mentioned yesterday I have now done. Since doing so, the slowness / inability to connect hasn’t happened - so the server app appears to be working fine and no longer napping.

For the client - I’ve added logic to the ‘Activate’ step - which basically forces a refresh. This means, if it does napp - upon being woken again, it’ll be updated.
I’ve also added logic to set the defaults … as per the other thread. Testing this afternoon seemed all good - will see how tomorrow goes with these two changes.

thanks for the feedback / advice.

Kent.

I can’t check right now but I don’t think we added the plist key to prevent app nap
That would be a relevant thing to check

[quote=159519:@Kent Lendrum]For the client - I’ve added logic to the ‘Activate’ step - which basically forces a refresh. This means, if it does napp - upon being woken again, it’ll be updated.
I’ve also added logic to set the defaults … as per the other thread. Testing this afternoon seemed all good - will see how tomorrow goes with these two changes.[/quote]
Excellent, am glad to hear you’ve done this. Apple, is constantly forcing us developers to adapt, not always when we have the time to do so, and I’m tired of chasing Apple (especially with the colossal amount of issues in Yosemite).

In my humble experience, taking the time to understand how to solve the problem correctly, leads to less problems down the road. If you start finding yourself using virtual duct tape… Your almost certainly destined for failure.

@Christian_Schmitz

NSProcessInfo takes multiple options for an activity. How do you do multiple options in the example you had? For instance, to add the flag for NSActivitySuddenTerminationDisabled. How can I tell if this is really working?

[code] dim Activity as NSProcessInfoActivityMBS // property in your window, control, thread, app
dim AllowAppNap as boolean // allow or not?

dim ProcessInfo as NSProcessInfoMBS = NSProcessInfoMBS.processInfo
if AllowAppNap then
Activity = nil
else
// disable sleep to let us make something…
Activity = ProcessInfo.beginActivity( Bitwise.BitAnd(NSProcessInfoMBS.NSActivityBackground, NSProcessInfoMBS.NSActivitySuddenTerminationDisabled ), “Backup running”)
end if[/code]

Please don’t use BitAnd. Use BitOr to add them.

@Christian_Schmitz

Understand - bitor.

With the latest Xojo, using NSProcessInfoMBS.NSActivityBackground does not prevent the app from being put to sleep.

I have an app that runs 24/7 that polls a network every 30 seconds, and OS X Yosemite still puts it to sleep with NSProcessInfoMBS.NSActivityBackground flagged.

I am trying to figure out not only how to prevent this, but to know ahead of time that whatever I have tried will work, as this is a mission critical app.

Did you read NSProcessInfo documentation?
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSProcessInfo_Class/index.html

So you use beginActivity call and keep the activity object in a global property, so it doesn’t go away too early?