Post

Replies

Boosts

Views

Created

-[NSWorkspace openApplicationAtURL:configuration:completionHandler:] error after startup
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
0
0
476
Feb ’22
macOS 10.12.4 NSButton After adding CAGradientLayer, button title is not displayed
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!
3
0
731
Nov ’22
Sleep State Notification Inconsistencies on MacBook Devices When Unplugged
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.
1
0
114
Aug ’25
Compatibility Issues with Main Event Loop in macOS 26 Beta
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?
0
1
175
Aug ’25
Get interface MTU
Hi,all Is there any API to get the mtu of the interface on MacOS.
Replies
0
Boosts
0
Views
474
Activity
Aug ’21
-[NSWorkspace openApplicationAtURL:configuration:completionHandler:] error after startup
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
Replies
0
Boosts
0
Views
476
Activity
Feb ’22
macOS 10.12.4 NSButton After adding CAGradientLayer, button title is not displayed
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!
Replies
3
Boosts
0
Views
731
Activity
Nov ’22
Sleep State Notification Inconsistencies on MacBook Devices When Unplugged
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.
Replies
1
Boosts
0
Views
114
Activity
Aug ’25
Compatibility Issues with Main Event Loop in macOS 26 Beta
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?
Replies
0
Boosts
1
Views
175
Activity
Aug ’25