Construct and manage a graphical, event-driven user interface for your macOS app using AppKit.

AppKit Documentation

Post

Replies

Boosts

Views

Activity

App crash on the the app launch in Xcode 16 RC in the 10.13 device due to QuciklookUI framework.
Process: Notebook (Beta) [4365] Path: /private/var/folders/*/Notebook (Beta).app/Contents/MacOS/Notebook (Beta) Identifier: com.zoho.notebook.macbeta Version: 5.5 (55008) Code Type: X86-64 (Native) Parent Process: ??? [1] Responsible: Notebook (Beta) [4365] User ID: 501 Date/Time: 2024-09-13 22:03:59.056 +0530 OS Version: Mac OS X 10.13.6 (17G14042) Report Version: 12 Anonymous UUID: 7CA3750A-2BDD-3FFF-5940-E5EEAE2E55F5 Time Awake Since Boot: 4300 seconds System Integrity Protection: disabled Notes: Translocated Process Crashed Thread: 0 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: DYLD, [0x1] Library missing Application Specific Information: dyld: launch, loading dependent libraries Dyld Error Message: Library not loaded: /System/Library/Frameworks/QuickLookUI.framework/Versions/A/QuickLookUI Referenced from: /private/var/folders/*/Notebook (Beta).app/Contents/MacOS/Notebook (Beta) Reason: image not found
3
1
328
Sep ’24
autoreleasepool still gives me a memory leak
So I have this program that displays events on the window using NSWindow and a NSTextField. Basically it tracks the mouse position and the keyboard state. I created a simple class named MyEventWindow: // // MyEventWindow.h // AppTest #ifndef MyEventWindow_h #define MyEventWindow_h @interface MyEventWindow : NSWindow { } @property(nonatomic, strong) NSTextField* label; @property(nonatomic, strong) NSString* labelText; - (BOOL)windowShouldClose:(id)sender; - (instancetype) init; - (void) setLabelText:(NSString *)labelText; @end @implementation MyEventWindow -(instancetype) init { self = [super initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable) backing:NSBackingStoreBuffered defer:NO]; if( !self ) { return nil; } [self setTitle: @"Event tracker"]; [self setIsVisible: YES]; _label = [[NSTextField alloc] initWithFrame:NSMakeRect(5, 100, 290, 100)]; [_label setBezeled: NO]; [_label setDrawsBackground: NO]; [_label setEditable: NO]; [_label setSelectable: YES]; NSFont *currentFont = [_label font]; NSFont *resizedFont = [NSFont fontWithName:[currentFont fontName] size:18]; NSFont *boldFont = [[NSFontManager sharedFontManager] convertFont:resizedFont toHaveTrait:NSFontBoldTrait]; // convert the bold font to have the italic trait NSFont *boldItalicFont = [[NSFontManager sharedFontManager] convertFont:boldFont toHaveTrait:NSFontItalicTrait]; [_label setFont:boldItalicFont]; [_label setTextColor:[NSColor colorWithSRGBRed:0.0 green:0.5 blue:0.0 alpha:1.0]]; // attach label to the damn window [[self contentView] addSubview: _label]; return self; } -(BOOL)windowShouldClose:(id)sender { return YES; } -(void) setLabelText:(NSString *)newText { [_label setStringValue: newText]; } @end #endif /* MyEventWindow_h */ Then in the main file I try to handle event loop manually: // // main.m #import <Cocoa/Cocoa.h> #import "MyEventWindow.h" NSString* NSEventTypeToNSString(NSEventType eventType); NSString* NSEventModifierFlagsToNSString(NSEventModifierFlags modifierFlags); int main(int argc, char* argv[]) { @autoreleasepool { [NSApplication sharedApplication]; MyEventWindow* eventWindow = [[MyEventWindow alloc] init]; [eventWindow makeKeyAndOrderFront:nil]; NSString* log = [NSString string]; // my own message loop [NSApp finishLaunching]; while (true) { @autoreleasepool { NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate: [NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; log = [NSString stringWithFormat:@"Event [type=%@ location={%d, %d} modifierFlags={%@}]", NSEventTypeToNSString([event type]), (int)[event locationInWindow].x, (int)[event locationInWindow].y, NSEventModifierFlagsToNSString([event modifierFlags])]; //NSLog(@"log: %@", log); [eventWindow setLabelText: log]; [NSApp sendEvent:event]; //[NSApp updateWindows]; // redundant? } } } return 0; } NSString* NSEventTypeToNSString(NSEventType eventType) { switch (eventType) { case NSEventTypeLeftMouseDown: return @"LeftMouseDown"; case NSEventTypeLeftMouseUp: return @"LeftMouseUp"; case NSEventTypeRightMouseDown: return @"RightMouseDown"; case NSEventTypeRightMouseUp: return @"RightMouseUp"; case NSEventTypeMouseMoved: return @"MouseMoved"; case NSEventTypeLeftMouseDragged: return @"LeftMouseDragged"; case NSEventTypeRightMouseDragged: return @"RightMouseDragged"; case NSEventTypeMouseEntered: return @"MouseEntered"; case NSEventTypeMouseExited: return @"MouseExited"; case NSEventTypeKeyDown: return @"KeyDown"; case NSEventTypeKeyUp: return @"KeyUp"; case NSEventTypeFlagsChanged: return @"FlagsChanged"; case NSEventTypeAppKitDefined: return @"AppKitDefined"; case NSEventTypeSystemDefined: return @"SystemDefined"; case NSEventTypeApplicationDefined: return @"ApplicationDefined"; case NSEventTypePeriodic: return @"Periodic"; case NSEventTypeCursorUpdate: return @"CursorUpdate"; case NSEventTypeScrollWheel: return @"ScrollWheel"; case NSEventTypeTabletPoint: return @"TabletPoint"; case NSEventTypeTabletProximity: return @"TabletProximity"; case NSEventTypeOtherMouseDown: return @"OtherMouseDown"; case NSEventTypeOtherMouseUp: return @"OtherMouseUp"; case NSEventTypeOtherMouseDragged: return @"OtherMouseDragged"; default: return [NSString stringWithFormat:@"%lu", eventType]; } } NSString* NSEventModifierFlagsToNSString(NSEventModifierFlags modifierFlags) { NSString* result = @""; if ((modifierFlags & NSEventModifierFlagCapsLock) == NSEventModifierFlagCapsLock) result = [result stringByAppendingString:@"CapsLock, "]; if ((modifierFlags & NSEventModifierFlagShift) == NSEventModifierFlagShift) result = [result stringByAppendingString:@"NShift, "]; if ((modifierFlags & NSEventModifierFlagControl) == NSEventModifierFlagControl) result = [result stringByAppendingString:@"Control, "]; if ((modifierFlags & NSEventModifierFlagOption) == NSEventModifierFlagOption) result = [result stringByAppendingString:@"Option, "]; if ((modifierFlags & NSEventModifierFlagCommand) == NSEventModifierFlagCommand) result = [result stringByAppendingString:@"Command, "]; if ((modifierFlags & NSEventModifierFlagNumericPad) == NSEventModifierFlagNumericPad) result = [result stringByAppendingString:@"NumericPad, "]; if ((modifierFlags & NSEventModifierFlagHelp) == NSEventModifierFlagHelp) result = [result stringByAppendingString:@"Help, "]; if ((modifierFlags & NSEventModifierFlagFunction) == NSEventModifierFlagFunction) result = [result stringByAppendingString:@"Function, "]; return result; } in main I added a second @autoreleasepool inside the while loop it seemed to decrease memory usage significanly, however if I keep moving my mouse a lot the memory usage will still increase. I don't think this should be happening since the labelText is being destroying and recreated each iteration, is something wrong with my code? Why do I have a memory leak here? Any feedback regarding the code is also appreciated Cheers
1
0
312
Sep ’24
PrintCore API is lagging on the Sequoia
The performance of the PrintCore API on macOS Sequoia system has significantly deteriorated. When switching between page options in the print dialog, the application hangs. It can be observed through Instruments that the execution time of PrintCore() is higher on the Sequoia system than on the Sonoma system. 479.00 ms 17.0% 0 s PMBaseObject::PMBaseObject(char const*) 456.00 ms 16.2% 0 s PMBaseObject::~PMBaseObject()
0
0
234
Sep ’24
NSMutableAttributedString and NSTextTable
I'm using NSTextTable to format panels of stand-out text within body text. Paragraphs within the panel are handled as individual NSTextTableBlocks within the table. Each block is added to the NSMutableParagraphStyle that is part of the attributed string within the block's attributes. That's all fine and it works. But... Occasionally I see undrawn lines within the panel. These disappear (or sometimes appear) when the parent window (and thus the NSTextView holding the rendered attributed string) is resized. Lines do not always appear, and when they do they are not always in the same place. The height of the gap varies. I see this behaviour with these panels and with tables. What's common to both cases is not only the use of NSTextTable and NSTextTableBlock etc., but crucially (I think) the use of block margins. If I disable margins (which looks OK for the panels, but isn't right for tables), the problem disappears. So, a bug or (more likely) I'm missing a key part of view rendering or margin set up. But what? Code here: https://github.com/smittytone/PreviewMarkdown/blob/930f5f32aa0b3b77ec3f4f53436a79e10bb26f18/Markdown%20Previewer/Styler.swift#L882 Running 14.6.1 on an M3. I'm using TextKit 1 because I'm using an NSLayoutManager subclass to override certain text underlines (not used in panels as outlined above, or tables).
1
0
173
Sep ’24
How can I fix CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError:
I created a simple application which displays a window with a sample text and I'm supposed to use an alert when the user chooses to close the application, if he presses ok in the alert the application will close, if he presses cancel it goes on. So pretty simple code, I have a window class: // // MyWindow.h // AppTest // // Created by sanya on 11/09/24. // #ifndef MyWindow_h #define MyWindow_h @interface Window : NSWindow { NSTextField* label; } - (instancetype)init; - (BOOL)windowShouldClose:(id)sender; @end @implementation Window -(instancetype)init { label = [[[NSTextField alloc] initWithFrame:NSMakeRect(5, 100, 290, 100)] autorelease]; [label setStringValue:@"Hello, World!"]; [label setBezeled:NO]; [label setDrawsBackground:NO]; [label setEditable:YES]; [label setSelectable:YES]; [label setTextColor:[NSColor colorWithSRGBRed:0.0 green:0.5 blue:0.0 alpha:1.0]]; [label setFont:[[NSFontManager sharedFontManager] convertFont:[[NSFontManager sharedFontManager] convertFont:[NSFont fontWithName:[[label font] fontName] size:45] toHaveTrait:NSFontBoldTrait] toHaveTrait:NSFontItalicTrait]]; [super initWithContentRect:NSMakeRect(0, 0, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO]; [self setTitle:@"Hello world (label)"]; [[self contentView] addSubview:label]; [self center]; [self setIsVisible:YES]; return self; } - (BOOL)windowShouldClose:(id)sender { BOOL bClose = NO; CFOptionFlags responseFlags = 0; // Display the alert CFUserNotificationDisplayAlert( 0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, CFSTR("Alert Title"), CFSTR("This is a message displayed in the alert."), CFSTR("OK"), CFSTR("Cancel"), NULL, &responseFlags ); if (responseFlags == kCFUserNotificationDefaultResponse) { NSLog(@"User clicked OK"); bClose = YES; } else if (responseFlags == kCFUserNotificationAlternateResponse) { NSLog(@"User clicked Cancel"); } if( bClose ) [NSApp terminate:sender]; return bClose; } @end #endif /* MyWindow_h */ And in the main function I just initialize it: int main(int argc, const char * argv[]) { [NSApplication sharedApplication]; [[[[Window alloc] init] autorelease] makeMainWindow]; [NSApp run]; } It seems to work but if click 'Cancel' on the dialog , xcode gives me the following warning: CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them So i'm obviously not doing this in the correct way, how can I fix this? Also, any feedback on this code as a whole is highly appreciated.
1
1
325
Sep ’24
View flashes when setting new PDFDocument in PDFView
I have a SwiftUI View containing a PDFView from PDFKit (via NSViewRepresentable). When setting a new PDFDocument the view flashes briefly with the background color before displaying the new document. Curiously the flashing is vastly reduced (but not eliminated) by calling layoutDocumentView() which should already be called from setDocument according to its documentation. struct SheetView: NSViewRepresentable { var pdf: PDFDocument? func makeNSView(context: Context) -> PDFView { let pdfView = PDFView() pdfView.displaysPageBreaks = false pdfView.displayMode = .singlePage pdfView.pageShadowsEnabled = false pdfView.autoScales = true return pdfView } func updateNSView(_ pdfView: PDFView, context: Context) { if pdf != pdfView.document { pdfView.document = pdf pdfView.layoutDocumentView() // reduces flashing but does not eliminate it } } }
1
0
265
Sep ’24
How to instantiate subclass of NSDocumentController?
Hello, I want to subclass NSDocumentController, but I could not find the information in Apple document how to subclass. According to ChatGPT, it can be instantiated by [MyDocumentController sharedDocumentController]; before NSApplicationMain() as the following code. It seems working well in my test environment. int main(int argc, const char * argv[]) { [MyDocumentController sharedDocumentController]; NSApplicationMain(argc, argv); } But, I am not sure whether it is officially correct to instantiate so early (before calling NSApplicationMain). Is there any official information what is correct way to instantiate subclass of NSDocumentController?
1
0
312
Sep ’24
How to simulate a mouse click on an iPad connected as an external display
Hello. What API or framework to use to simulate a mouse click on an iPad connected as an external display? An iPad connected to the Mac via USB in a mode "Linked keyboard and mouse". What is the way to simulate a mouse click at a specific coordinate at such a display? So far I tried to simulate a click with CGEvent like so if let eventDown = CGEvent(mouseEventSource: source, mouseType: .leftMouseDown, mouseCursorPosition: point, mouseButton: .left), let eventUp = CGEvent(mouseEventSource: source, mouseType: .leftMouseUp, mouseCursorPosition: point, mouseButton: .left) { eventDown.post(tap: .cghidEventTap) usleep(500_000) eventUp.post(tap: .cghidEventTap) } but it seems it does not work even on the main display. I set the point to the coordinate outside of the app window so that on a click another app should be focused but it does not happen on a simulated click. I also tried to find a way to get a mouse coordinate on the external screen with addLocalMonitorForEvents. If I listen for the event NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { event in debugPrint("NSEvent.mouseLocation:", NSEvent.mouseLocation) return event } it only works when the cursor is on the main screen and stops reporting as soon as the mouse enters the iPad. So, any advice is welcomed on which direction I should look.
0
0
286
Sep ’24
How do I get available printer list
I am trying to get the list of printers using NSPrinter.printerNames, but it doesn't return any items. static func getPrinterList() -> [(name: String, isAvailable: Bool)] { let printerNames = NSPrinter.printerNames return printerNames.map { name in let isAvailable = NSPrinter(name: name) != nil return (name: name, isAvailable: isAvailable) } } The printerNames is a empty string array. I checked the settings for printers and screens, and there is a printer device listed. I need to set something else?
2
0
346
Aug ’24
Cannot remove an observer <TUINSCursorUIController 0x600001844340> for the key path "visible" from <NSSavePanel 0x10ff05200> because it is not registered as an observer.
I have two NSTextField as an accessoryView of NSSavePanel. When I try to change focus in between them with a caps lock on the whole panel will crash. This will also happen when NSTextField if focused with caps lock on and i press cmd+tab (app switching). This happens on Sonoma + Sequoia beta. On top I have noticed editing NSTextField in accessoryView is completely broken on Sonoma and I can only edit it ONLY when the textfiled is using bindings. I am trying to find a workaround for the caps lock indicator being displayed. The only idea I have ATM is to observe NSApp.windows and look for TUINSWindow and force close it when it's visible. Is there any other workaround to prevent this crash? https://youtu.be/BCVjZH7684U Sample code: import Cocoa class ViewController: NSViewController { let savePanel = NSSavePanel() override func viewDidLoad() { super.viewDidLoad() let view = NSGridView(views: [[NSTextField(string: "111111")], [NSTextField(string: "22222222")]]) savePanel.accessoryView = view } override func viewWillAppear() { savePanel.runModal() } } Crash report: Cannot remove an observer <TUINSCursorUIController 0x600001844340> for the key path "visible" from <NSSavePanel 0x10ff05200> because it is not registered as an observer. ( 0 CoreFoundation 0x000000019a2522ec __exceptionPreprocess + 176 1 libobjc.A.dylib 0x0000000199d36158 objc_exception_throw + 60 2 Foundation 0x000000019b30436c -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 628 3 Foundation 0x000000019b3040a4 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 136 4 TextInputUIMacHelper 0x0000000253d9e598 -[TUINSCursorUIController deactivate:] + 416 5 AppKit 0x000000019dbda3e4 -[NSTextInputContext deactivate] + 288 6 AppKit 0x000000019da3fff4 +[NSTextInputContext currentInputContext_withFirstResponderSync:] + 228 7 AppKit 0x000000019da4f084 -[NSView _setWindow:] + 692 8 AppKit 0x000000019db7d880 -[NSTextView(NSPrivate) _setWindow:] + 216 9 AppKit 0x000000019e4da778 __21-[NSView _setWindow:]_block_invoke.146 + 268 10 CoreAutoLayout 0x00000001a2aba588 -[NSISEngine withBehaviors:performModifications:] + 88 11 AppKit 0x000000019da4f4b4 -[NSView _setWindow:] + 1764 12 AppKit 0x000000019da7712c -[NSView removeFromSuperview] + 168 13 AppKit 0x000000019dc7c0e8 -[_NSKeyboardFocusClipView removeFromSuperview] + 56 14 AppKit 0x000000019dbc5474 -[NSWindow endEditingFor:] + 368 15 AppKit 0x000000019da770d0 -[NSView removeFromSuperview] + 76 16 AppKit 0x000000019dc7c0e8 -[_NSKeyboardFocusClipView removeFromSuperview] + 56 17 AppKit 0x000000019dc7be00 -[NSCell endEditing:] + 452 18 AppKit 0x000000019dc7b994 -[NSTextField textDidEndEditing:] + 264 19 CoreFoundation 0x000000019a1d2144 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148 20 CoreFoundation 0x000000019a2663d8 ___CFXRegistrationPost_block_invoke + 88 21 CoreFoundation 0x000000019a266320 _CFXRegistrationPost + 440 22 CoreFoundation 0x000000019a1a0678 _CFXNotificationPost + 768 23 Foundation 0x000000019b2bd2c4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88 24 AppKit 0x000000019dc7b5fc -[NSTextView(NSSharing) resignFirstResponder] + 668 25 AppKit 0x000000019db2ca80 -[NSWindow _realMakeFirstResponder:] + 196 26 AppKit 0x000000019dcc1764 -[NSWindow _makeParentWindowHaveFirstResponder:] + 76 27 ViewBridge 0x00000001a296c8c0 -[NSAccessoryViewWindow makeFirstResponder:] + 80 28 AppKit 0x000000019dbdbb9c -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3148 29 AppKit 0x000000019db67504 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 288 30 AppKit 0x000000019db67210 -[NSWindow(NSEventRouting) sendEvent:] + 284 31 ViewBridge 0x00000001a296cecc -[NSAccessoryViewWindow sendEvent:] + 64 32 AppKit 0x000000019e2304f0 -[NSApplication(NSEventRouting) sendEvent:] + 1604 33 AppKit 0x000000019dc6df6c -[NSApplication _doModalLoop:peek:] + 276 34 AppKit 0x000000019dc6ce38 __35-[NSApplication runModalForWindow:]_block_invoke_2 + 56 35 AppKit 0x000000019dc6cde4 __35-[NSApplication runModalForWindow:]_block_invoke + 108 36 AppKit 0x000000019dc6c6b0 _NSTryRunModal + 100 37 AppKit 0x000000019dc6c570 -[NSApplication runModalForWindow:] + 292 38 AppKit 0x000000019e690490 -[NSSavePanel runModal] + 340 39 SavePanelAccessory 0x0000000100435ad4 $s18SavePanelAccessory14ViewControllerC14viewWillAppearyyF + 60 40 SavePanelAccessory 0x0000000100435b0c $s18SavePanelAccessory14ViewControllerC14viewWillAppearyyFTo + 36 41 AppKit 0x000000019db387f4 -[NSViewController _sendViewWillAppear] + 32 42 AppKit 0x000000019db386bc -[NSViewController _windowWillOrderOnScreen] + 80 43 AppKit 0x000000019e4e7b38 -[NSView _windowWillOrderOnScreen] + 56 44 AppKit 0x000000019e4e7ba4 -[NSView _windowWillOrderOnScreen] + 164 45 AppKit 0x000000019db38570 -[NSWindow _doWindowWillBeVisibleAsSheet:] + 40 46 AppKit 0x000000019e4fc418 -[NSWindow _reallyDoOrderWindowAboveOrBelow:] + 1028 47 AppKit 0x000000019e4fcfec -[NSWindow _reallyDoOrderWindow:] + 64 SHORTENED
0
0
310
Aug ’24
Problem with status bar moving horizontally in apps that only support portrait
Our app supports only portrait mode. And in some cases, the status bar moves horizontally, as shown in the video below. We have confirmed that this problem does not appear in OS versions 15.3.1 and lower. The problem occurs on OS 16 and 17. https://youtu.be/CiR5LcoBI5c At the point when the problem appears, the code simply subscribes to data through the interval scheduler. The code is below: At that point, set autoUpdate to true. private let autoUpdateTimer = Observable<Int>.interval(.seconds(20), scheduler: MainScheduler.asyncInstance) private var autoUpdate = BehaviorRelay<Bool>(value: false) autoUpdateTimer .withLatestFrom(autoUpdate) .filter { $0 } .withLatestFrom(Observable.combineLatest(deviceSeq,currentChannel,channel) .map { ($0.0, $0.1, 1, $0.2?.property?.unitCount ?? 1) } .flatMap(dependency.usecase.pubAutoStatus) .subscribe().disposed(by: disposeBag) I would appreciate any feedback on how I can resolve this.
1
0
254
Aug ’24
NSAttributedString draw in rect
I need to draw an attributed string into a given rectangle. The string's height should be the same as the rectangle's height. This should work with any font a user chooses. To make it a bit more complicated, the string should also fill the rect if it consists only of uppercase characters or only of lowercase characters. I am using NSLayoutManager to find the "best" font size for the selected font and the given recht and it works quite good with some fonts but with others it doesn't. Seems like the computed font size is always a bit too small and for some fonts it seems like the baseline must be corrected. Unfortunately I didn't find a way to calculate a baseline offset that really works with any font. I attached some sample images showing the issue. Just posting this to make sure I am not running in the complete wrong direction. Any help would be highly appreciated. Thanks!
13
0
692
Aug ’24
NSView VisibleRect Behavior in Different macOS Versions
I am use XCode 15.2 and macOS SDK 14.2. I placed an NSView inside the NSClipView of an NSScrollView, the NSView is smaller than the NSClipView, always centered. On Ventura, regardless of whether clipsToBounds is set, the bounds and visibleRect of the NSView are the same. However, on Sonoma, even after overriding -(BOOL)clipsToBounds { return YES; }, the bounds is correct, but the visibleRect (the red rect) is still the same size as the NSClipView, results in the text is not clipped. Am I missing something or doing something wrong? How can I make the visibleRect of the NSView consistent with its bounds?
3
0
253
Aug ’24
Dynamic Notch
If anyone there is familiar with Cocoa, can you please help with the following issue: How to make the NSWindow resize based on the contentView? Here is a video of the problem: https://drive.google.com/file/d/19LN98xdF9OLcqRZhMJsGGSa0dgMvj_za/view?usp=sharing Thanks!
0
0
324
Aug ’24
iOS18 AudioPlaybackIntent respond too slow when app not launched
here's my case, i develop a control widget, user can push a controlwidget to play music without open the app. i bind a AudioPlaybackIntent to the widget. when user click the widget, the app will receive the intent and start to play music. it works perfect when app running in background or foreground. but when app not launched, the respond is too slow, it takes several seconds to start play music. is there any way to make the respond faster when app not launched? if i want to do something when app not launched, what should i do?
2
0
557
Aug ’24
NSInternalInconsistencyException: Cancel Potential Unregister Timer not set
This issue happens in my app and I don't know why, I cannot get even useful info from stack. it's all about AppKit and HIToolBox or CoreFoundation. I initially suspect it might be related to NSTimer. However I think this wouldn't cause such a crash. I am currently out of ideas and unable to provide more detailed and effective information (if I could, that would be great, and I also hope to have it). I search Apple Doc and it tell me NSInternalInconsistencyException occurs when an internal assertion fails and implies an unexpected condition within the called code. So I want to get some clues from you why I encounter such an issue. @interface MyApp () { scoped_refptr<base::SequencedTaskRunner> task_runner_; } @implementation MyApp //... - (void)start { // ... self.timer = [NSTimer scheduledTimerWithTimeInterval:60 // call every 60 sec target:self selector:@selector(logAndKill:) userInfo:info repeats:YES]; - (void)logAndKill { if (needLog) { // ... } else { task_runner_->PostTask(FROM_HERE, base::BindOnce(^() { [self.timer invalidate]; self.timer = nil; }));
0
0
313
Aug ’24
App icon
Dear all, I'm building my first MacOs app. I've created my app icon and add it to AppIcon folder, but when I'm building the application the icon shows in the dock of the screen with no rounded borders like all the other apps. I'm attaching here the icon and as you can see it has sharp edges. It is the same way in which it shows on the dock. Why? Has anybody experienced the same? Thanks for the support in advance, A.
1
0
555
Aug ’24
NSSavePanel accessory view doesn't react to enter keypress
I have a textfield in accessory view of NSSavePanel. For user convenience there are default actions supported natively by macOS (such as pressing Enter, keyEquivalent). However this doesn't work for enter under Sonoma. Escape key works. Is enter keypress dangerous for malicious actors so it's not supported? I have workaround below but I am not confident if I am not violating sandbox (future proof). Original code demonstrating the issue: class ViewController: NSViewController, NSTextFieldDelegate, NSControlTextEditingDelegate { let savePanel = NSSavePanel() override func viewDidLoad() { super.viewDidLoad() let customView = NSView() let textField = NSTextField(string: "11111111") textField.delegate = self // to get focus using tab keypress savePanel.accessoryView = textField } override func viewWillAppear() { savePanel.runModal() } } Workaround: // variable set to true in delegate method controlTextDidEndEditing var didUseTextFieldWithEnterPressed = false override func performKeyEquivalent(with event: NSEvent) -> Bool { if #unavailable(macOS 14) { return super.performKeyEquivalent(with: event) } guard let panel, didUseTextFieldWithEnterPressed == true, event.type == .keyDown && (event.keyCode == UInt16(kVK_Return) || event.keyCode == UInt16(kVK_ANSI_KeypadEnter)) else { return super.performKeyEquivalent(with: event) } return panel.performKeyEquivalent(with: event) }
0
0
298
Aug ’24