Posts

Post not yet marked as solved
1 Replies
525 Views
There is a tips popup window in my program, I set it to close after 3 seconds, and the makeKeyAndOrderFront function is never called on it. However, the following error will appear during operation: Warning: -[NSWindow makeKeyWindow] called on NSWindow 0x7fb... which returned NO from -[NSWindow canBecomeKeyWindow] I'd like to know if there are any other function calls that would cause the above warning? Or how can I troubleshoot and remove this warning.
Posted Last updated
.
Post not yet marked as solved
0 Replies
202 Views
In my program, I overridden the NSTextField as follows: @interface CustomTextField:NSTextField @end @implementation CustomTextField - (BOOL)performKeyEquivalent:(NSEvent *)event { NSUInteger flags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; NSString *modifierFlagsString = @""; if ((flags & NSEventModifierFlagControl) != 0) { modifierFlagsString = [modifierFlagsString stringByAppendingString:@"Control+"]; } NSString *key = [[event charactersIgnoringModifiers] uppercaseString]; NSString *hkString = [modifierFlagsString stringByAppendingString:key]; self.stringValue = [NSString stringWithFormat:@"*%@", hkString]; return YES; } In short, my goal is to capture the function key + key event when NSTextField is entered, and then display it in the specified format. But if the key pressed does not contain a shortcut, I want no input. How can I achieve this? Because I tried keydown and other methods but none of them seemed correct.
Posted Last updated
.
Post not yet marked as solved
1 Replies
321 Views
I'm writing a program that requires accessibility permissions, and I use AXIsProcessTrustedWithOptions to confirm and direct the user to the accessibility interface for authorization. According to conventional implementation, after the accessibility interface is opened, the system will automatically add the corresponding program, and the user only needs to turn on the permissions. But now, with accessibility turned on, I don't see my program loading automatically. Next, I tried to add it manually, click + on the accessibility interface, select the program I built and then add it. But when I clicked Add, my program was not successfully added. The accessibility interface still did not see my program being loaded, and the user could not open permissions for it. I think this has nothing to do with whether it is a development version, because I tried other debug programs developed and compiled with xcode and they were able to be added normally. So I want to know, what are the reasons why it cannot be added? Which parts should I check from?
Posted Last updated
.
Post not yet marked as solved
1 Replies
410 Views
I'm trying to write a program where I want to get the text content selected by the mouse by detecting mouse movements. My main code is as follows: #import "AppDelegate.h" #import <Cocoa/Cocoa.h> @interface AppDelegate () @property (strong) IBOutlet NSWindow *window; @property (nonatomic) CFMachPortRef eventTap; @end CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { if (type == kCGEventLeftMouseDown) { NSLog(@"Mouse down."); } else if (type == kCGEventLeftMouseUp) { NSLog(@"Mouse up."); NSRunningApplication *currentApp = [[NSWorkspace sharedWorkspace] frontmostApplication]; AXUIElementRef appElement = AXUIElementCreateApplication(currentApp.processIdentifier); AXUIElementRef windowElement; AXError error = AXUIElementCopyAttributeValue(appElement, kAXFocusedWindowAttribute, (CFTypeRef *)&windowElement); if (error != kAXErrorSuccess) { NSLog(@"Could not get focused window. Error code: %d", error); return event; } AXValueRef selectedTextValue; error = AXUIElementCopyAttributeValue(windowElement, kAXSelectedTextAttribute, (CFTypeRef *)&selectedTextValue); if (error != kAXErrorSuccess) { NSLog(@"Could not get selected text. Error code: %d", error); return event; } NSString *selectedText = (__bridge_transfer NSString *)selectedTextValue; NSLog(@"Selected text: %@", selectedText); } return event; } @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application self.eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventLeftMouseUp), myCGEventCallback, NULL); if (self.eventTap) { CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.eventTap, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); CGEventTapEnable(self.eventTap, true); CFRelease(runLoopSource); // Don't release eventTap here } else { NSLog(@"Failed to create event tap"); } } - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application if (self.eventTap) { CFRelease(self.eventTap); } } - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app { return YES; } @end I confirmed that I have granted "Accessibility" permissions to my program and the application I am trying to access is xcode or when I try to access the chrome interface I get the same error kAXErrorCannotComplete. So how do I deal with this problem? Or is there any other way to achieve my target function? PS: I solved the above error by set App Sandbox Value (NO) in the entitlements, but I don't know if this is a reasonable solution. And then AXUIElementCopyAttributeValue generated another error kAXErrorFailure. How should I troubleshoot this problem ?
Posted Last updated
.
Post marked as solved
4 Replies
838 Views
Currently, I have implemented a project that includes network extension and system extension entitlements. When I create the profile using the development method, I get exactly the right entitlement matching. For example: create app id (identifier) create a profile, associate with the corresponding app id, generate the profile and download it locally. In xcode, fill in the corresponding app id in Bundle Identifier, such as com.***.test.app, and fill in the corresponding development profile in Provisioning Profile. At this point I was able to achieve a complete and correct program compiling and running. Now, I want to distribute this app by developer id. According to https://developer.apple.com/developer-id/ , I have several questions remain: I followed this method https://developer.apple.com/help/account/create-certificates/create-developer-id-certificates/ to create a distribution certificate and created two new profiles (distribute- developer id), which is associated with the existing bundle ID (com.***.test.app, com.***.test.extension). But when I import the corresponding provisioning profile in xcode, it shows error: Provisioning profile "***" doesn’t match the entitlement file’s value for the com.apple.developer.networking.networkextension entitlement. But isn't the corresponding entitlement information already selected when the app id is set? Why is the profile of the development type feasible, but the profile of the developer id is not feasible? I have made relevant settings according to this method https://developer.apple.com/documentation/xcode/preparing-your-app-for-distribution/, and I don’t seem to need the hardened runtime and sandbox related content, so I don't have any settings. Maybe apple events in hardened runtime is necessary? Submitting software to apple notarization seems to be a more trustworthy behavior for users, but at this stage I just want to simply implement distribution for program testing, so I chose export in archives-distribute app-developer id, and in the follow-up The same error as in question 1 appeared in the profile selection of the profile: Profile doesn't match the entitlements file's value for the com.apple.developer.networking.networkextension entitlement. So, overall: One is how to create the correct developer id profile? My two entitlements files are as follows: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;com.apple.developer.networking.networkextension&lt;/key&gt; &lt;array&gt; &lt;string&gt;content-filter-provider&lt;/string&gt; &lt;/array&gt; &lt;key&gt;com.apple.developer.system-extension.install&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.app-sandbox&lt;/key&gt; &lt;false/&gt; &lt;key&gt;com.apple.security.files.user-selected.read-only&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;com.apple.developer.networking.networkextension&lt;/key&gt; &lt;array&gt; &lt;string&gt;content-filter-provider&lt;/string&gt; &lt;/array&gt; &lt;key&gt;com.apple.security.app-sandbox&lt;/key&gt; &lt;false/&gt; &lt;key&gt;com.apple.security.application-groups&lt;/key&gt; &lt;array&gt; &lt;string&gt;$(TeamIdentifierPrefix)com.example.app-group&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/plist&gt; Second, is Apple notarization necessary?
Posted Last updated
.
Post not yet marked as solved
7 Replies
677 Views
Although I was able to get simplefirewall to work, I still have a problem. When I start it for the first time (start button), every target traffic will be captured normally, but when I pause (stop button) and start again (start button), the same target traffic will not be captured. If I want it to work again, I need to stop it from xcode start the program again. What is the reason? Any suggestions?
Posted Last updated
.
Post marked as solved
1 Replies
383 Views
Why is the local ip and port obtained through localEndpoint 0.0.0.0:0 when handlenewflow (outbound flow), the remote ip and port are normal, and the local/remote ip and port for the inbound flow are normal. override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict { guard let socketFlow = flow as? NEFilterSocketFlow, let remoteEndpoint = socketFlow.remoteEndpoint as? NWHostEndpoint, let localEndpoint = socketFlow.localEndpoint as? NWHostEndpoint else { return .allow() } os_log("Got a new flow with local endpoint %@, remote endpoint %@", localEndpoint, remoteEndpoint) let flowInfo = [ FlowInfoKey.localPort.rawValue: localEndpoint.port, FlowInfoKey.remoteAddress.rawValue: remoteEndpoint.hostname ] let flowInfo2 = [ FlowInfoKey2.localAddress.rawValue: localEndpoint.hostname, FlowInfoKey2.remotePort.rawValue: remoteEndpoint.port ] …………………… }
Posted Last updated
.
Post not yet marked as solved
1 Replies
755 Views
I'm trying to debug the official network extension sample code simplefirewall. Although it has been able to run normally and pops up user pop-up windows for the specified filter conditions, there are still two warnings and errors: [Window] Warning: Window NSWindow 0x1007315f0 ordered front from a non-active application and may order beneath the active application's windows. [default] CGSWindowShmemCreateWithPort failed on port 0 For the first warning, I followed the method given in https://developer.apple.com/forums/thread/729496 and added windo.makeKey() and window.orderFrontRegardless(), but this warning didn't go away. As for the second default, I haven't been able to find the corresponding root cause and solution of the problem. I would like to ask, can anyone give me some advice? Xcode:Version 14.3.1 (14E300c)
Posted Last updated
.
Post marked as solved
1 Replies
398 Views
I am trying to use the example of the network extension. Now I have completed the necessary profile configuration and other content. After I try to run, a corresponding small window will pop up, but no matter how long after I click start, no matter what connection I send, it does not respond and display. I would like to know how to open a connection on the port being filtered? And then to make the SimpleFirewall work as expected?
Posted Last updated
.