logo
On this page

How to handle the App Nap issue on macOS system?

2021-09-09
Products / Plugins:In-app chat
Platform / Framework:macOS

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;
}

Previous

How to handle the issue of video stuttering or audio-video out of sync when using OBS to publish and SDK to play?

Next

How to use bitmask?

On this page

Back to top