How to handle the App Nap issue on macOS system?
Problem Description
Due to the App Nap mechanism on macOS system, if some App windows are placed in the background for a period of time without use and the window is completely invisible, macOS will put the App into a nap state. In this state, the App's CPU and other system resources usage will be limited, in a state similar to "sleep".
In this case, there may be a ZIM long connection heartbeat timeout, causing the connection to be disconnected.
Solution
Developers can prevent the system from putting the application into a nap state by declaring to disable App Nap.
If developers need to disable App Nap, they only need to add the following code in the AppDelegate.m file:
#include <Foundation/NSProcessInfo.h>
#include <Foundation/Foundation.h>
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
......
......
NSActivityOptions options = NSActivityUserInitiatedAllowingIdleSystemSleep;
NSString *reason = @"ZIM needs it's network connection. NO NAPPING!";
self.activity = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:reason];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
......
......
[[NSProcessInfo processInfo] endActivity:self.activity];
self.activity = nil;
}
