I have a standard Mac project created using Xcode templates with Storyboard. I manually removed the window from the Storyboard file and use ViewController.h as the base class for other ViewControllers. I create new windows and ViewControllers programmatically, implementing the UI entirely through code.
However, I've discovered that on all macOS versions prior to macOS 26 beta, the application would trigger automatic termination due to App Nap under certain circumstances. The specific steps are:
Close the application window (the application doesn't exit immediately at this point)
Click on other windows or the desktop, causing the application to lose focus (though this description might not be entirely accurate - the app might have already lost focus when the window closed, but the top menu bar still shows the current application immediately after window closure)
The application automatically terminates
In previous versions, I worked around this issue by manually executing [[NSApplication sharedApplication] run]; to create an additional main event loop, keeping the application active (although I understand this isn't an ideal approach).
However, in macOS 26 beta, I've found that calling [[NSApplication sharedApplication] run]; causes all NSButton controls I created in the window to become unresponsive to click events, though they still respond to mouse enter events.
Through recent research, I've learned that the best practice for preventing App Nap automatic termination is to use [[NSProcessInfo processInfo] disableAutomaticTermination:@"User interaction required"]; to increment the automatic termination reference count.
My questions are:
Why did calling [[NSApplication sharedApplication] run]; work properly on macOS versions prior to 15.6.1?
Why does calling [[NSApplication sharedApplication] run]; in macOS 26 beta cause buttons to become unresponsive to click events?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
There are inconsistent behaviors in sleep/wake notification callbacks across different MacBook devices and macOS versions when the device is not connected to power, with or without external displays, entering sleep mode by closing the lid, and waking up from sleep by opening the lid.
When monitoring the following Objective-C notifications:
NSWorkspaceScreensDidSleepNotification
NSWorkspaceScreensDidWakeNotification
NSWorkspaceWillSleepNotification
NSWorkspaceDidWakeNotification
Different devices exhibit varying notification trigger patterns:
Some devices trigger all four notifications properly
Some devices fail to trigger NSWorkspaceScreensDidWakeNotification
Some devices fail to trigger NSWorkspaceDidWakeNotification
Some devices fail to trigger NSWorkspaceWillSleepNotification
These inconsistencies make it challenging to implement reliable sleep/wake detection logic across different MacBook models and macOS versions.
The purpose of the following code is to achieve a gradient background color In newer versions, it looks fine, but in macOS 10.12.4, the title of the button doesn't appear
- (void)setGradient:(NSArray<__kindof NSColor *> *)colorArr StartPoint:(CGPoint)startPoint EndPoint:(CGPoint)endPoint {
self.wantsLayer = YES;
CAGradientLayer *gradinentlayer = [CAGradientLayer layer];
NSMutableArray *array = [NSMutableArray array];
for (NSColor *color in colorArr) {
[array addObject:(id)color.CGColor];
}
gradinentlayer.colors = array;
gradinentlayer.startPoint = startPoint;
gradinentlayer.endPoint = endPoint;
gradinentlayer.frame = self.bounds;
[self.layer insertSublayer:gradinentlayer atIndex:0];
}
How do I make the title text appear, other than adding a subview?
Any help would be appreciated!
There is a LoginItem in my app that launches the application. It works fine with approximately the following code snippet:
NSString *mainAppIdentifier = @"com.xxxxxxx";
NSArray *runningApps = [[NSWorkspace sharedWorkspace]runningApplications];
BOOL isRunning = NO;
for (NSRunningApplication *application in runningApps) {
if ([application.bundleIdentifier isEqualToString:mainAppIdentifier]) {
isRunning = YES;
break;
}
}
if (!isRunning) {
[[NSDistributedNotificationCenter defaultCenter]addObserver:self selector:@selector(terminate) name:@"killLauncher" object:mainAppIdentifier];
NSString *path = [[NSBundle mainBundle]bundlePath];
NSMutableArray *components = [NSMutableArray arrayWithArray:path.pathComponents];
[components removeLastObject];
[components removeLastObject];
[components removeLastObject];
[components addObject:@"MacOS"];
[components addObject:@"appName"];
NSString *newPath = [NSString pathWithComponents:components];
[[NSWorkspace sharedWorkspace]launchApplication:newPath];
Since 11.0, launchApplication: is deprecated in favour of openApplicationAtURL:. When I try to modify it and restart the device, the following error appears:
Application "xxx" does not have permission to open "xxxx"
How should I do
Hi,all
Is there any API to get the mtu of the interface on MacOS.
We use NetworkExtension to develop a Mac VPN application with the includedRoutes attribute set to defaultRoute. We hope that when the DNS of the physical port changes or the network is switched in the VPN connection state, the DNS information of the current "en" port can be obtained. And optimize accordingly.
We have found two ways to obtain DNS
SCDynamicStoreRef ds = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("myapp"), NULL, NULL);
CFDictionaryRef dr = SCDynamicStoreCopyValue(ds, CFSTR("State:/Network/Global/DNS"));
NSArray *routerArray;
if (dr) {
CFArrayRef router = CFDictionaryGetValue(dr, CFSTR("ServerAddresses"));
routerArray = [NSArray arrayWithArray:(__bridge NSArray *)router];
CFRelease(dr);
}
CFRelease(ds);
AND
res_state res = malloc(sizeof(struct __res_state));
int result = res_ninit(res);
if ( result == 0 ) {
for ( int i = 0; i res-nscount; i++ ) {
NSString *s = [NSString stringWithUTF8String : inet_ntoa(res-nsaddr_list[i].sin_addr)];
[dnsArray addObject:s];
}
}
res_nclose(res);
They work perfectly when there is no VPN connection, but when the VPN connected is established, they can only get the DNS of the "utun" port, which does not meet our needs. We hope to get the DNS of the "en" port.
Can we get the DNS information of the specified port?
This is very important to us.
please help us
I created a VPN application using NEPacketTunnelProvider and set some ip lists for includedRoutes. My matchDomains is set to @[@“”], and now all my DNS resolution traffic will be sent from the utun port
Now there is a requirement. We have a domain name whose DNS resolution traffic does not want to be sent from the utun port. What should I do?
NEDNSSettings *DNSSettings does not provide a blacklist of DNS domain names
Although I know this is not very good, I still tried to add a large number of domain whitelists to matchDomains, but it seems that there is a bottleneck. When I add more than 5000 domains to matchDomains, the Internet will report an error Unknown host