Post

Replies

Boosts

Views

Activity

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
54
2w
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
646
Nov ’22
-[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
432
Feb ’22
A question about how to obtain the physical port DNS when connected to the VPN
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
2
0
536
Mar ’21
NEPacketTunnelProvider DNS traffic sending
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
2
0
635
Jan ’21