Post

Replies

Boosts

Views

Activity

Mac Catalyst UIWindowScene requestGeometryUpdateWithPreferences: doesn't respect provided systemFrame origin.
On app launch I'm trying to specify a reasonable initial value for the window's frame. Using the recommended API I create a UIWindowSceneGeometryPreferencesMac object and pass it to -requestGeometryUpdateWithPreferences:errorHandler: in -scene:willConnectToSession:options: This method respects the value passed in as the size but does not seem to respect the requested origin. Initially I'm always placed at origin 0, 0 for the first window which doesn't look particularly good. I think I'd like to be inset on the x-axis a bit, or maybe even position the window in the center of the screen on app launch. Is there anyway to get more control over the window frame on Mac Catalyst?
3
0
1.1k
Dec ’22
Mac Catalyst on Multiple Displays: Using UIWindowSceneGeometryPreferencesMac to set a default window size causes new windows to open on the wrong display
In the WWDC 2022 video "Bring your iOS App to the Mac" there is sample code which shows the recommended way to set the default window size for a new window. According to the presenter it is considered good practice to do this in -scene:willConnectToSession:options: CGRect systemFrame = scene.effectiveGeometry.systemFrame; CGRect newFrame = CGRectMake(systemFrame.origin.x,                                      systemFrame.origin.y,                                      defaultWindowSize.width,                                      defaultWindowSize.height);  UIWindowSceneGeometryPreferencesMac *geometryPrefs = [[UIWindowSceneGeometryPreferencesMac alloc]initWithSystemFrame:newFrame];         [scene requestGeometryUpdateWithPreferences:geometryPrefs errorHandler:^(NSError * _Nonnull error)          {         //Error         }]; So I have a button in my UI that opens a new window that uses this window scene delegate class. I have a laptop and external display connected. Now my app's window is on the external display and when I click the button the opens the new window, the new window opens on the laptop's main display (the display physically attached). This is wrong. Setting the requestingScene property on UISceneActivationRequestOptions makes no difference, the new window still opens on the wrong display no matter what. If I comment out the above code that sets the initial window size... the window opens on external display as expected (but now I've lost my window size).
3
0
1.4k
Dec ’22
Mac Catalyst: UIActivityViewController's completionWithItemsHandler block is never called when a system provided UIActivity is selected.
According to the UIActivityViewController documentation for UIActivityViewController's completionWithItemsHandler: Upon the completion of an activity, or the dismissal of the activity view controller, the view controller’s completion block is executed. You can use this block to execute any final code related to the service. However when invoking the "Messages" or "Mail" actions in the UIActivityViewController this block is never called. I'm presenting the UIActivityViewController in a popover. Simple to reproduce. Just do this on Mac Catalyst in a table view delegate (sorry for the poor code formatting but it is hard to format code well on these forums). -(UISwipeActionsConfiguration*)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {     UIContextualAction *shareAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal                     title:@"Share"               handler:^(UIContextualAction *action,                                                                                       UIView * _Nonnull sourceView,                                                                                       void (^_Nonnull completionHandler)(BOOL))     {         [self showPopoverWithSourceItem:sourceView completionWithItemsHandler:^(UIActivityType  _Nullable activityType,                                                                                 BOOL completed,                                                                                 NSArray * _Nullable returnedItems,                                                                                 NSError * _Nullable activityError) {             //This block isn't called when Messages/Mail activities are selected. Probably other too but that's all I tested.             completionHandler(completed); //Need to call the UIContextualAction's completionHandler here to close up the swipe actions.         }];     }];     shareAction.image = [UIImage systemImageNamed:@"square.and.arrow.up.fill"];     UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[shareAction]];     return config; } -(void)showPopoverWithSourceItem:(id<UIPopoverPresentationControllerSourceItem>)sourceItem       completionWithItemsHandler:(UIActivityViewControllerCompletionWithItemsHandler)handler {     NSURL *shareLink = [NSURL URLWithString:@"https://www.apple.com"];          UIActivityViewController *activityViewController = [[UIActivityViewController alloc]initWithActivityItems:@[shareLink]                                                                                         applicationActivities:nil];          activityViewController.completionWithItemsHandler = handler;             activityViewController.modalPresentationStyle = UIModalPresentationPopover;     UIPopoverPresentationController *presentationController;     presentationController = (UIPopoverPresentationController*)activityViewController.presentationController;     presentationController.sourceItem = sourceItem;     presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;     [self presentViewController:activityViewController animated:YES completion:nil]; } Run that and choose "Mail" or "Messages" in the activity view controller. The table view remains swiped after the activity is invoked and the popover is dismissed. Now if you click outside the popover without invoking an activity the popover dismisses and the completionWithItemsHandler is called. Related but different UIActivityViewController/UIActivity bug I reported here yesterday: https://developer.apple.com/forums/thread/722003 I will file a bug on this and post the number here soon. Can I please work a full day without running into a system bug in this framework....just one day..please. I wouldn't be so disgruntled about all this if my obvious bug reports actually got fixed in a reasonable amount of time but I've been a developer long enough to know that I'm lucky if they get fixed for macOS 14, if ever.
1
0
701
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
643
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.1k
Oct ’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
421
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
722
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.2k
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
608
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
854
Feb ’23
WKWebView on Mac Catalyst elementFullscreenEnabled set to YES on WKPreferences but it does not work
Setting elementFullscreenEnabled property to YES on WKPreferences is not honored on Mac Catalyst.  WKWebViewConfiguration *webViewConfig = [[WKWebViewConfiguration alloc]init];  WKPreferences *prefs = [[WKPreferences alloc]init]; prefs.elementFullscreenEnabled = YES;   webViewConfig.preferences = prefs; //then create the WKWebView.. I load a Youtube url in the WKWebView. Youtube complains that the browser doesn't support full screen. Is there a workaround? Full screen does work in an AppKit app though using the exact same API...though it causes an Autolayout crash (I will be making another thread about that separate issue shortly).
4
0
1.3k
Oct ’23
WKWebView on Mac causes Autolayout Crash After Exiting Full screen Video
I configured a WKWebView to support full screen elements like this:  WKWebViewConfiguration *webViewConfig = [[WKWebViewConfiguration alloc]init]; WKPreferences *prefs = [[WKPreferences alloc]init];  prefs.elementFullscreenEnabled = YES;  webViewConfig.preferences = prefs; //Create a WKWebView with the configuration and load a url like Youtube that supports playing videos in full screen.... Then I run the app and play a YouTube video. I enter full screen. Then I exit full screen and I hit an Autolayout crash. 0 libobjc.A.dylib 0x188365820 objc_msgSend + 32 1 CoreAutoLayout 0x1904ed82c -[NSLayoutConstraint _layoutEngine] + 36 2 CoreAutoLayout 0x1904ee3c0 __55+[NSLayoutConstraint _addOrRemoveConstraints:activate:]_block_invoke + 160 3 CoreAutoLayout 0x1904d4514 -[NSISEngine withBehaviors:performModifications:] + 88 4 CoreAutoLayout 0x1904ee238 +[NSLayoutConstraint _addOrRemoveConstraints:activate:] + 308 5 WebKit 0x1a82777fc -[WKFullScreenWindowController finishedExitFullScreenAnimationAndExitImmediately:] + 936 6 WebKit 0x1a7d63868 -[WKFullScreenWindowController windowDidExitFullScreen:] + 44 7 CoreFoundation 0x1887a6560 CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 148 8 CoreFoundation 0x188844044 ___CFXRegistrationPost_block_invoke + 88 9 CoreFoundation 0x188843f8c _CFXRegistrationPost + 440 10 CoreFoundation 0x188777b64 _CFXNotificationPost + 708 11 Foundation 0x18966738c -[NSNotificationCenter postNotificationName:object:userInfo:] + 88 12 AppKit 0x18c4a3210 -[NSWindow(NSFullScreen) _didExitFullScreen] + 336 13 AppKit 0x18c2aa3ac -[_NSExitFullScreenTransitionController _doAfterExitFullScreen] + 304 14 AppKit 0x18c2acb28 ___NSRunLoopTimerCreateWithHandler_block_invoke + 56 15 CoreFoundation 0x1887cb54c CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 32 16 CoreFoundation 0x1887cb1f4 __CFRunLoopDoTimer + 940 17 CoreFoundation 0x1887cad4c __CFRunLoopDoTimers + 356 18 CoreFoundation 0x1887b0734 __CFRunLoopRun + 1896 19 CoreFoundation 0x1887af878 CFRunLoopRunSpecific + 612 20 HIToolbox 0x191e8ffa0 RunCurrentEventLoopInMode + 292 21 HIToolbox 0x191e8fde4 ReceiveNextEventCommon + 672 22 HIToolbox 0x191e8fb2c _BlockUntilNextEventMatchingListInModeWithFilter + 72 23 AppKit 0x18ba3584c _DPSNextEvent + 632 24 AppKit 0x18ba349dc -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728 25 AppKit 0x18ba28e0c -[NSApplication run] + 464 26 AppKit 0x18ba00250 NSApplicationMain + 880 27 AppKitWKWebviewProjectForWebInspector 0x102fbbf80 main + 44 (main.m:14) 28 dyld 0x1883a7e50 start + 2544
2
0
789
Feb ’23