Post

Replies

Boosts

Views

Activity

UIKit doesn't always retain custom UIViewControllerTransitioningDelegate?
So I'm using a custom presentation controller which requires me to specify a transitioningDelegate on the view controller before presenting it like this: vcToPresent.modalPresentationStyle = UIModalPresentationCustom; vcToPresent.transitioningDelegate = transitionDelegate; Now I want to enforce a particular view controller to always use my custom presentation controller. Unfortunately I cannot just override the presentationController getter and return my own custom class; I have to make a transitioning delegate and an additional animator (and my custom presentation controller can animate alongside it). To have a view controller use my own presentation controller I have to do this: -(void)presentCustomVC { MyViewController *vcToPresent = [MyViewController makeViewController]; MyTransitioningDelegate *transitionDelegate = [[MyTransitioningDelegate alloc]init]; vcToPresent.modalPresentationStyle = UIModalPresentationCustom; vcToPresent.transitioningDelegate = transitionDelegate; [self presentViewController:vcToPresent animated:YES completion:nil]; } So I have to copy this transitioningDelegate set up code in every view controller that presents MyViewController. I can make the API look a little better by creating a factory method in MyViewController like this: +(MyViewController*)makeViewController { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; MyViewController *theVC = [storyboard instantiateInitialViewController]; MyTransitioningDelegate *transDelegate = [[MyTransitioningDelegate alloc]init]; theVC.modalPresentationStyle = UIModalPresentationCustom; theVC.transitioningDelegate = transDelegate; return theVC; } The problem with that is the transitioningDelegate gets deallocated right away (before the view controller can be presented). The transitioningDelegate property on UIViewController is weak for some reason. Shouldn't the transitioningDelegate property be declared strong? My custom transitioningDelegate has no strong reference to the presented view controller? If I add a redundant property to MyViewController like this: @property (nonatomic,strong) MyTransitioningDelegate *strongTransDelegate; And then do this: theVC.modalPresentationStyle = UIModalPresentationCustom; theVC.transitioningDelegate = transDelegate; theVC.strongTransDelegate = transitionDelegate; All seems to work well. When the view controller is dismissed the transitioning delegate is deallocated. However I'm assuming the transitioningDelegate property on UIViewController was declared as weak for a reason? I don't want to accidentally create a retain cycle in some unforeseen circumstance. Documentation makes no mention on who should be the "owner" of the transitioning delegate?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
531
Jun ’23
WKContentRuleListStore fails to compile "Too many rules in JSON array" What's the max?
When trying to compile a rule list via WKContentRuleListStore's -compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler: method I'm getting the following error: ** Rule list compilation failed Too many rules in JSON array.** The max number of rules allowed in a WKContentRuleList doesn't seem to be documented (or I couldn't find it). Does anyone know what the limit is? Thanks
Topic: Safari & Web SubTopic: General Tags:
1
0
567
Jul ’23
SwiftUI Previews: Is There a Way to Have the Preview Take Over the Entire Window and Collapse the Source Code Pane?
In a SwiftUI source file Xcode displays a window with a Split View. The first split is the source code and the second split is the preview. My question is, is there a way for me to have the preview take over the entire window width (I want to collapse the source code pane and just look at the preview)? I can easily collapse the Preview pane by dragging the split to the right to collapse (but it doesn't work in reverse). I also can toggle the preview pane by going to Editor -> Canvas in the Menu bar. Currently I'm using SwiftUI just to get a live preview of UIKit view controllers so I'm not interested in looking at the SwiftUI source code, though I imagine displaying a full window preview in a separate window would be useful for SwiftUI developers too. You could edit the source code on one monitor and have the preview window on an external display. Is this not possible?
1
1
1.7k
Jul ’23
NSLayoutConstraint 'UIView-Encapsulated-Layout-Height' on UICollectionViewListCell Breaking Self Sizing Content View Constraint
I'm using compositional layout with UICollectionView. In a particular section I configure the compositional layout to use an estimated height because I want self sizing items determined by Autolayout Constraints. Now I have a custom content configuration with autolayout constraints. At runtime I hit this log about conflicting constraints: [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) [...] <NSLayoutConstraint:0x6000024af160 UIImageView:0x120745520.height == 130 (active)> <NSLayoutConstraint:0x6000024af2a0 MyCustomContentView :0x120748d60.height >= 1.04839*UIImageView:0x120745520.height (active)> <NSLayoutConstraint:0x6000024b08c0 'UIView-Encapsulated-Layout-Height' UICollectionViewListCell:0x1214392f0.height == 44 (active)> Will attempt to recover by breaking constraint <NSLayoutConstraint:0x6000024af160 UIImageView:0x120745520.height == 130 (active)> The "UIView-Encapsulated-Layout-Height" on UICollectionViewListCell with a value of 44.0 appears to be a constraint created by the system. I'm not sure why a hard coded height of 44.0 is being used when the compositional layout is returning a section that only uses estimated heights (created via NSCollectionLayoutDimension estimatedDimension). Any ideas how I can avoid this? I'm not using custom UICollectionView cells but I am using a custom content configuration and a custom content view and setting my content configuration on a UICollectionViewListCell.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
2
1.5k
Aug ’23
Mac Catalyst Modally Presented View Controllers Not Working in Xcode Live Previews
I have a UIViewController subclass I'm using in Mac Catalyst. This view controller is only ever presented as a sheet. When I try to make a live preview for it the preview is displayed a gigantic size (not the sheet's actual size at runtime). I made a separate thread about this: https://developer.apple.com/forums/thread/738641 In order to be able to preview the view controller for Mac Catalyst at the desired size I figured I'd present it on another view controller. #Preview { let wrapperVC = WrapperViewController() return wrapperVC } //In WrapperViewController override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if (firstViewDidAppear) { firstViewDidAppear = false view.backgroundColor = UIColor.yellow let realVC = ActualVCIWantToPreview() realVC.modalPresentationStyle = .formSheet present(realVC, animated: false); } } But that's not working. However if I change the device from Mac to iPad it does work so it appears modal presentations aren't working for Live Previews on Mac Catalyst (unless I'm doing something wrong but Xcode is reporting no errors it just isn't showing my presented view controller).
1
0
785
Sep ’23
StoreKit Receipt Refresh Error (Mac Catalyst) Error Domain=AMSErrorDomain Code=203 "Bag Load Failed Unable to retrieve app-receipt-create because we failed to load the bag."
Been testing all day and receipt loading has been working (testing in sandbox) on Mac Catalyst. I'm using StoreKit1. All of a sudden I'm getting the following error when refreshing a receipt: ** Error Domain=AMSErrorDomain Code=203 "Bag Load Failed Unable to retrieve app-receipt-create because we failed to load the bag." UserInfo={NSDebugDescription=Bag Load Failed Unable to retrieve app-receipt-create because we failed to load the bag.** Sandbox server down?
1
0
2.1k
Oct ’23
"Customize Toolbar" on NSToolbar Causes Autolayout Constraints Violation on macOS Sonoma
I have a customizable NSToolbar (using in a Mac Catalyst app "optimized for Mac"). When I right click and choose "Customize toolbar" I get the following error: Conflicting constraints detected: ( "<NSLayoutConstraint:0x6000014a24e0 NSToolbarItemGroupView:0x13de568c0.width <= 88.5 (active)>", "<NSAutoresizingMaskLayoutConstraint:0x6000014f5f90 h=--& v=--& NSToolbarItemGroupView:0x13de568c0.width == 89 (active)>" ). Will attempt to recover by breaking <NSLayoutConstraint:0x6000014a24e0 NSToolbarItemGroupView:0x13de568c0.width <= 88.5 (active)>. Unable to simultaneously satisfy constraints: ( "<NSLayoutConstraint:0x6000014a24e0 NSToolbarItemGroupView:0x13de568c0.width <= 88.5 (active)>", "<NSAutoresizingMaskLayoutConstraint:0x6000014f5f90 h=--& v=--& NSToolbarItemGroupView:0x13de568c0.width == 89 (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x6000014a24e0 NSToolbarItemGroupView:0x13de568c0.width <= 88.5 (active)> Set the NSUserDefault >NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have ->[NSWindow visualizeConstraints:] automatically called when this happens. And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.
1
0
652
Oct ’23
WKWebView Unrecognized Selector Sent to Instance: WebAVPlayerLayer - startRedirectingVideoToLayer:forMode:
I'm using WKWebView in a Mac Catalyst app (not sure if using Catalyst makes a difference but it seems WKWebView doesn't get the "full" Mac version AppKit apps do so maybe it does). When a website has a video playing and if I click the button that I guess is a Picture in Picture button next to the "close" button the web kit process gets an unrecognized selector sent to instance exception. -[WebAVPlayerLayer startRedirectingVideoToLayer:forMode: <-- Unrecognized selector. In debugging mode at least my app doesn't crash the video continues to play and the WKWebview is unresponsive to user interaction. I have to force quit my app. -- I'm on Sonoma 14.0
1
1
784
Oct ’23
Programmatically Launch an macOS Action Extension?
Is there a way to programmatically launch a macOS Action Extension (related documentation: https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Action.html) I'm aware how to create "Action Extensions" but they only seem to be activated from NSTextView "rollover" button. Say I know there is an action extension that works on a particular type of data can I launch it from my app? Obviously we can launch "regular" apps with NSWorkspace by bundle iD but I was wondering if there is any API where my app could directly launch an action extension as the "host app" programmatically.
1
0
767
Oct ’23
WKWebView -resumeAllMediaPlayback: deprecated Replacement is -setAllMediaPlaybackSuspended:completionHandler:
I see the -resumeAllMediaPlayback: says the replacement method is -setAllMediaPlaybackSuspended:completionHandler: I don't believe suspending and resuming media playback are matching actions, which would mean -resumeAllMediaPlayback: doesn't have a replacement API? The deprecated -resumeAllMediaPlayback: method doesn't seem to work on Sonoma (pauseAllMediaPlaybackWithCompletionHandler: does work but resume does not).
Topic: Safari & Web SubTopic: General Tags:
1
0
564
Oct ’23
A Web Page's Javascript Causing an Error in My WKUserScript Loaded in a Custom Content World
I have a global variable in WKUserScript declared as a const in Javascript. I load this script in a custom WKContentWorld I create with my own name (not the pageWorld or default world). There some nasty javascript out there on most popular sites. I noticed that unhandled errors on the page can break stop my WKUserScript from working. In one particular case there is this nasty script on page for ads that uses document.write like so: b.contentWindow.document.write(e), b.contentWindow.document.close() And the web inspector shows an error here "Can't create duplicate variable: 'MyGlobalVariableNameInsMyUserScriptHere'" This script being used on the web page is going to end up getting blocked. But my question is this, isn't using my own content world supposed to protect me against this type of thing? This global javascript variable (an array) is global in my javascript file and holds some data in it but it is not inserted into the DOM. Shouldn't document.write/document.close calls from the page not cause this type of error in my user script? And if the entire DOM is being rewritten shouldn't a new script (representing my user script) be created from scratch? I think I can avoid the error by changing the variable from const to var (haven't tried yet). But is this how it's supposed to be?
Topic: Safari & Web SubTopic: General Tags:
1
0
608
Oct ’23
CoreML PyTorch Conversion More Samples?
I'm trying to convert a PyTorch forward Transformer model to CoreML but am running into several issues, like these errors: "For mlprogram, inputs with infinite upper_bound is not allowed. Please set upper. bound" 570 • to a positive value in "RangeDim)" for the "inputs" param in ct.convert().' raise NotImplementedError ( 259 "inplace_ops pass doesn't yet support append op inside conditional" Are there any more samples besides https://developer.apple.com/videos/play/tech-talks/10154 The sample in that video an imageType is used as input but in my model text is the input (and the output). I also get warned that converting "torch script" is experimental but in the video it says it a torch script is required to convert (though I know the video is a few years old).
1
0
1.2k
Nov ’23
OSLog Line Numbers & Source File Only Shown On Mouse Hover in Tiny Text?
For awhile I've wrapped OSLog in my own macros to include the line number and source file the logging statement originates from in debug mode because OSLog didn't include that info in console output (until recently). Now I noticed the source code file and line number of the logging statement isn't being shown (I have all the metadata switches turned on in Xcode's console "Metadata Options" popover). Then I realized it is being shown, only on mouse hover over the logging statement in very tiny text. The text is barely readable (on mouse hover). Why would viewing the line number require me to move the mouse cursor over a logging statement? It doesn't look pretty at all (hiding information behind mouse hover) and even if it did look pretty, this is the console for programmers and we don't care about such nonsense.
1
0
1k
Dec ’23