Post

Replies

Boosts

Views

Created

Mac Catalyst Determine Default Size of NSToolbarItems When Creating them with UIBarButtonItems and SF Symbol Images?
Is there a way to programmatically determine the default size of an NSToolbarItem when creating them on Mac Catalyst like so:  UIImage *downArrowImage = [UIImage systemImageNamed:@"arrow.down"]; UIBarButtonItem *goDownUIBarButtonItem = [[UIBarButtonItem alloc]initWithImage:downArrowImage style:UIBarButtonItemStylePlain target:nil action:@selector(navigateDownard:)];  NSToolbarItem *nsToolbarItem = [NSToolbarItem itemWithItemIdentifier:itemIdentifier barButtonItem:goDownUIBarButtonItem]; Why am I asking? I need to create a toggle toolbar item (which requires me to change the toolbar item's image when the toggle is flipped. I can do this by using NSUIViewToolbarItem and embedding a UIButton. But when you feed an SF Symbol image to UIButton and call sizeToFit on it it doesn't generate a view that matches the size of UIBarButtonItems for all the other NSToolbarItems next to it. I can hard code size constraints in like this to make it size properly:  NSLayoutConstraint *width = [theUIButtonToEmbedInToolbarItem.widthAnchor constraintEqualToConstant:32.0];     NSLayoutConstraint *height = [theUIButtonToEmbedInToolbarItem.heightAnchor constraintEqualToConstant:32.0]; //activate these constraints and embed the UIButton in the NSToolbarItem. And that's works but I'm guessing the size so the layout could break in a OS update. I tried just feeding an SF Symbol image to NSToolbarItem's image property directly but then the toolbar item doesn't draw at all (edit: this is only true when using an NSToolbarItem subclass, which I created to change the toolbar item's image itself when the toggle property is flipped) //Inside my NSToolbarItem subclass. -(void)setOn:(BOOL)isOn { if (_on != on) { _on = isOn; self.image = (isOn) ? self.onImage : self.offImage; } } So when using NSToolbaritem's image property directly setting the image property works fine, this means I have to track the toggle state externally which is possible but definitely not as nice). Edit: Actually if forgot to modify my toolbar item subclass to subclass NSToolbarItem directly (was subclassing NSUIViewToolbarItem when I was first experimenting with using UIButton). Using the image property on NSToolbarItem directly works for me. So I'm happy. I still think it'd be useful for clients that need to embed custom views inside a NSToolbarItem to get some kind of size recommendation.
1
0
691
Dec ’22
UIMenuElement subclass that can take a target? Like UITargetedCommand?
When building context menus in UIKit I often have actions contained in a single method which can be invoked in different ways (from a UIButton, a UIBarButtonItem, etc.) I'd like to simply make a menu item with a target-action pair but UICommand/KeyCommand only takes a selector. It seems kind of silly to have the system enumerate the responder chain in cases where I know who the target is supposed to be and there can and should only be one target (also could unintentionally create bugs when a responder implementing the same method gets the call instead of the target you want). In AppKit you an easily do this with NSMenuItem. Could be a nice enhancement in UIKit. I know I can wrap the target in UIAction and call the selector in the action handler block but the code is kind of ugly and I'm not sure if there are edge cases where __weak __strong dance is required (in which case the code is even more long winded and ugly. I know swipe actions can occasionally create a retain cycle if you don't do __weak _ __strong dance). Unless there is a UIMenuElement subclass that provides this and I'm just not aware of it?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
648
Jan ’23
How come Crash Reports Don't Include the NSException name and reason when a crash is caused by a raised exception?
When running into a hard to reproduce crash that only occurs in a production build it would be helpful to get more detailed information about the thrown exception. As far as I can tell, Crash reports don't include the NSException's name, reason, or userInfo. Is there any reason why this isn't included in Crash reports provided to developers? Someone else asking something similar here: https://stackoverflow.com/questions/73327915/how-do-you-add-diagnostic-information-to-ios-crash-reports
1
1
787
Jan ’23
Exception: NSView this class is not key value coding-compliant for the key cell shortly after presenting UIDocumentPickerViewController on Mac Catalyst
Shortly after presenting a UIDocumentPickerViewController on Mac Catalyst the system throws this exception and I keep hitting my exception breakpoint: NSView: valueForUndefinedKey this class is not key value coding-compliant for the key cell. Appears to be related to the system using Touch Bar APIs (my app isn't currently using Touch Bar APIs directly but the NSOpenPanel created by UIDocumentPickerViewController is). #2 0x0000000198de2828 in -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] () #3 0x000000019884ef3c in -[NSObject(NSKeyValueCoding) valueForKey:] () #4 0x0000000200b75a68 in -[NSObject(UIAccessibilitySafeCategory) __axValueForKey:] () #5 0x0000000200b75960 in __57-[NSObject(UIAccessibilitySafeCategory) safeValueForKey:]_block_invoke () #6 0x0000000200b75f9c in -[NSObject(UIAccessibilitySafeCategory) _accessibilityPerformSafeValueKeyBlock:withKey:onClass:] () #7 0x0000000200b754d0 in -[NSObject(UIAccessibilitySafeCategory) safeValueForKey:] () #8 0x0000000222206b60 in -[NSTouchBarItemAccessibility__UIKit__AppKit _accessibilityPopulateAccessibiltiyInfoFromUIKit] () #9 0x0000000222206b1c in -[NSTouchBarItemAccessibility__UIKit__AppKit _itemViewMinSize:maxSize:preferredSize:stretchesContent:] () #10 0x000000019b3f70bc in -[NSCompressionGroupLayout item:minSize:maxSize:preferredSize:] () #11 0x000000019aff24f4 in -[NSTouchBarItemContainerView _updateMeasuredSizes] () #12 0x000000019aff2358 in -[NSTouchBarItemContainerView minSize] () #13 0x000000019accae98 in -[NSTouchBarLayout _aggregateWidthOfItems:sharesLeftEdge:sharesRightEdge:widthMeasurement:] () #14 0x000000019accb22c in -[NSTouchBarLayout _attributesOfItems:centerItems:givenSize:sharesLeftEdge:sharesRightEdge:xOrigin:] () #15 0x000000019acca930 in -[NSTouchBarLayout attributesOfItems:centerItems:givenSize:] () #16 0x000000019b52bbb0 in -[NSTouchBarView _positionSubviews] () #17 0x000000019b52ba6c in -[NSTouchBarView layout] () -- The exception does get caught (my app doesn't crash) but I hit the exception breakpoint over and over again while the NSOpenPanel is on screen which is annoying.
3
0
1.2k
Jan ’23
Is there a entry to specify the Mac idiom in a Settings.bundle for the SupportedUserInterfaceIdioms key?
The newer documentation about creating a Settings.bundle on Mac Catalyst simply links out to the Documentation Archive: https://developer.apple.com/library/archive/documentation/PreferenceSettings/Conceptual/SettingsApplicationSchemaReference/Articles/PSGroupSpecifier.html#//apple_ref/doc/uid/TP40007009-SW1 The SupportedUserInterfaceIdioms key is documented: Indicates that the element is displayed only on specific types of devices. The value of this key is an array of strings with the supported idioms. Include the string “Phone” to display the element on iPhone and iPod touch. Include the string to “Pad” to display it on iPad.  This key is available in iOS 4.2 and later. Is "Mac" a supported entry to specify a preference for the Mac idiom? It seems to work but I don't see any documentation for this.
1
0
429
Jan ’23
Mac Catalyst NSToolbar / Title Bar Doesn't Honor overrideUserInterfaceStyle value of the UIWindow
It is normal to have a preference like: “Always use Dark Mode” in an app to allow the user to opt in to Dark mode in the current app without turning it on System wide. On iOS you can manage this by detecting the change in the app preference and when it is turned on you set the overrideUserInterfaceStyle property on the UIWindow to UIUserInterfaceStyleDark. On Mac Catalyst however this does not work. If you set the overrideUserInterfaceStyle property to UIUserInterfaceStyleDark the NSWindow underneath doesn’t update to reflect dark mode. The titlebar doesn’t update for dark mode either. And neither does the NSToolbar. Only UIViewControllers inside the UIWindow reflect the overrideUserInterfaceStyle Ideally it would be great if there was a overrideUserInterfaceStyle property on UIApplication but there is not. Is there a way to force the NSWindow/NSToolbar created by Mac Catalyst to use a particular appearance (without an Appkit bundle)?
0
1
616
Jan ’23
Mac Catalyst UITabBarController with hidden tab bar wrapping view controllers inside the "More" navigation controller (not desired) when 7 or more tabs are embedded
I have a UITabBarController on Mac Catalyst. Since the UITabBar isn't really nice on Mac, I set the UITabBar to hidden. Then I create a Mac styled NSToolbar with selectable items and manually change the UITabBarController selection with the NSToolbar selection (like the UITabBar would do normally on iOS). This works fine until I select view controller at index 7 or greater. Then all of a sudden an iOS styled UINavigationBar appears. UITabBarController is wrapping view controllers at index 7 or greater in the "More Navigation Controller" which is not desired or needed (the window width is wide enough to avoid clipping, and the UITabBar is not even visible).
3
0
736
Feb ’23
Folder sharing with VZVirtioFileSystemDeviceConfiguration Not Working (Linux Guest)?
I'm trying to share a directory on my Mac with a virtual machine I created using the Virtualization framework. The virtual machine is running Fedora. I configure the share like this:  NSError *error = nil; if ([VZVirtioFileSystemDeviceConfiguration validateTag:tag error:&error]) { //Tag validates...   VZSharedDirectory *sharedDirectiory = [[VZSharedDirectory alloc]initWithURL:theURL readOnly:NO];    VZSingleDirectoryShare *singleDirectoryShare = [[VZSingleDirectoryShare alloc]initWithDirectory:sharedDirectiory]; VZVirtioFileSystemDeviceConfiguration *shareConfig = [[VZVirtioFileSystemDeviceConfiguration alloc]initWithTag:tag];  shareConfig.share = singleDirectoryShare;  virtualMachineConfiguration.directorySharingDevices = @[shareConfig]; } The virtual machine starts up without any errors but the shared directory is nowhere to be found. Anyone know where am I'm going wrong? Thanks in advance.
1
1
779
Feb ’23
WKWebView Loading HTML Strings Taking An Extremely Long Time On Mac Catalyst (Ventura 13.2.1)
I have an area in my app where I load local HTML strings in WKWebView. Loading is fast on iOS. These local HTML strings are small. On Mac Catalyst I added the ability to open this area of the UI in a new window scene (new window). And for some reason sometimes when I do this these simple HTML strings can take 10-15 seconds to load in the WKWebview in the new window. These HTML strings are super small. I key value observed the loading property of the WKWebview and I hold the current date just before calling -loadHTMLString:baseURL: Then when the web view completes loading I see how much time passed: -(void)observeValueForKeyPath:(NSString*)keyPath                      ofObject:(id)object                        change:(NSDictionary<NSKeyValueChangeKey,id>*)change                       context:(void*)context { if (object == self.webview && [keyPath isEqualToString:@"loading"]) { if (!self.webview.isLoading) {   NSTimeInterval timeInterval = [NSDate.date timeIntervalSinceDate:self.loadStartDate]; NSLog(@"Web view took %f seconds to load",timeInterval); } } else {   [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } Sometimes it is taking as long as 5 seconds to load a tiny HTML string. When opening these WKWebviews in the same window I don't get these long load times. But when I kick of WKWebView inside a new window scene I often do.
Topic: Safari & Web SubTopic: General Tags:
1
0
1.3k
Feb ’23
Enable WKWebView Web Inspector Under Mac Catalyst?
I'm trying to enable the web inspector on WKWebView in a Mac Catalyst app. I'm only doing this for debugging purposes. In the released the web inspector will not be enabled. Doing this under Mac Catalyst does not work:  WKPreferences *prefs = [[WKPreferences alloc]init];   [prefs _setDeveloperExtrasEnabled:YES]; //Assign the WKPreferences to a WKWebViewConfiguration and create the web view.. Is there any way to do this? Thanks in advance.
4
0
1.8k
Feb ’23
Mac Catalyst: Mac Specific Data Assets Don't Load from Asset Catalog via NSDataAsset
My configuration: A iOS app that supports Mac Catalyst. This Mac Catalyst app is “optimized for Mac” it is not scaled to match iPad. I open the asset catalog and add a “Data Asset” which is a .txt file. This is set to “Universal.” I add “Mac” variant for this data asset and I add a .txt with different text. I load the string at runtime like this: NSDataAsset *scriptData = [[NSDataAsset alloc]initWithName:@"TextDataAsset"]; NSString *loadedText = [[NSString alloc]initWithData:scriptData.data encoding:NSUTF8StringEncoding]; When I run that on Mac Catalyst the text loadedText is an empty string, which is wrong. Running on iOS I get the expected string. Is this the intended behavior? Am I supposed to use the "iPad" device for Mac assets (because I don't believe that is the case with images, etc.) In any case I filed FB12005255
0
0
620
Feb ’23
Mac Catalyst: UITableView Suddenly Randomly Selecting Rows After Deleting Row Via Swipe Action After a Bit of A Delay
I'm getting some new behavior I haven't seen before (on Venture 13.2.1) on UITableView. Steps to reproduce: A table view row is selected and I swipe to delete the selected row. After about a half of a second the table view selects another row. I'm not programmatically making a selection here after the swipe to delete. UIKit is doing it. I set a breakpoint in -tableView:didSelectRowAtIndexPath: and it is related to the focus system: #1 0x00000001b350b140 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:deselectPrevious:performCustomSelectionAction:] () #2 0x00000001b3512df8 in -[UITableView _didUpdateFocusInContext:withAnimationCoordinator:] () #3 0x0000000213b38988 in -[UITableViewAccessibility _didUpdateFocusInContext:withAnimationCoordinator:] () #4 0x00000001b2f54260 in __84-[UIFocusSystem _sendDidUpdateFocusNotificationsInContext:withAnimationCoordinator:]_block_invoke () #5 0x00000001b2f08944 in _UIFocusEnvironmentEnumerateAncestorEnvironments () #6 0x00000001b2f54480 in -[UIFocusSystem _sendNotificationsForFocusUpdateInContext:withAnimationCoordinator:usingBlock:] () #7 0x00000001b2f53ff0 in -[UIFocusSystem _sendDidUpdateFocusNotificationsInContext:withAnimationCoordinator:] () #8 0x00000001b2f53630 in -[UIFocusSystem _updateFocusWithContext:report:] () #9 0x00000001b2f5319c in -[UIFocusSystem updateFocusIfNeeded] () #10 0x00000001b2f561dc in __43-[UIFocusSystem _updateFocusUpdateThrottle]_block_invoke () #11 0x00000001b3725e70 in -[_UIAfterCACommitBlock run] () #12 0x00000001b37262cc in -[_UIAfterCACommitQueue flush] () #13 0x00000001b2851630 in _runAfterCACommitDeferredBlocks () #14 0x00000001b28513ac in _cleanUpAfterCAFlushAndRunDeferredBlocks () #15 0x00000001b28512c8 in _afterCACommitHandler () #16 0x00000001887b0db8 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION () #17 0x00000001887b0ca4 in __CFRunLoopDoObservers () This wasn't happening before. I'm not sure if it is related to the Ventura 13.2.1 update or if there is some minor tweak on my end that is causing this change in behavior though I'm not thrilling with UIKit making a selection without asking me about it. I could live with the automatic row selection if the next row below the deleted row was automatically selected but sometimes it is not. Sometimes UITableView is auto selecting a row two cells back which doesn't make any sense to me.
3
0
871
Feb ’23