Post

Replies

Boosts

Views

Activity

List row stay selected after back
Hi, I found a case that cause a list to never deselect the row when the back button is pressed. In the following code I modally present a list. When you select a row another list is displayed. If you select a row of the second list and you go back the row will stay selected. This is the code: struct ContentView: View { 		@State var modalVisible = false 		var body: some View { 				Button(action:{ 						self.modalVisible.toggle() 				}) { 						Text("Open modal") 				} 				.sheet(isPresented: $modalVisible) { 						NavigationView { 								List { 										NavigationLink("Item", destination: List { 												NavigationLink("Sub Item", destination: Text("If you go back the row will stay selected.")) 										})                 }             }         }     } } Does anyone know if there is a way to force the list to deselect the row when the back button is pressed? Thank you
2
0
2.2k
Mar ’21
iOS 15 navigation bar transition between large title and small title
Hi, On iOS 13 and iOS 14, if you have a navigation controller that use large titles and you push a controller that does not want a large title (navigationItem.largeTitleDisplayMode = .never) there is a smooth animation between the two navigation bar heights (from the large one to the small one). On iOS 15 the animation is missing and during the transition the pushed controller view top part is covered by the large title bar until the end of the transition. After the animation is done the height of the navigation bar suddenly becomes small. Here's the transition on iOS 14. The navigation bar height gradually changes from large to small: And here's the transition on iOS 15. The navigation bar height is not animated and remains the same until the end of the transition animation: I opened a bug report regarding this issue (FB9290717) but I want to know if someone has found a temporary fix for this. Thank you
2
0
3k
Jul ’21
PHCloudIdentifier without photo library access prompt
Hi, I'm currently let the user pick a photo using PHPickerViewController. The advantage of PHPickerViewController is that the user is not requested to grant photo access (no permission alerts). After the user picked the photo I need to take note of the local identifier and the cloud identifier (PHCloudIdentifier). For the local identifier no problem, I just use the assetIdentifier from the PHPickerResult. For obtaining the cloud identifier (PHCloudIdentifier, on iOS 15 only) I need to use the cloudIdentifierMappings method of PHPhotoLibrary. The problem of that method is that is causing the photo library access permission alerts to display. Someone know if there is another way to get the cloud identifier from a local identifier without having to prompt the user photo library access? Thank you
2
0
1.4k
Jan ’22
iOS 15 prewarming and didFinishLaunchingWithOptions
Hi, Just want to understand what is the current state of iOS 15 prewarming app delegate behaviour. There is a lot of confusion (and a lack of documentation) about which app delegate methods are called during prewarming. It's not clear if didFinishLaunchingWithOptions will be called or not during prewarming. A lot of applications are counting on UserDefaults and Keychain access in didFinishLaunchingWithOptions, but sadly these two features seems to be unavailable during prewarming causing issues. Some users say that this was the case before 15.4 and that from 15.4 the didFinishLaunchingWithOptions app delegate method is no more called during prewarming. Just want to know if we can have an official statement about this. It is safe, from iOS 15.4 onwards, to use UserDefaults and access Keychain in the didFinishLaunchingWithOptions app delegate method? Thank you
2
2
3k
Sep ’23
NSWindowDelegate windowShouldClose on Catalyst
Hi, I'm looking for a way to do something when the user presses the window red close button on a Catalyst app. For example, in some cases, I need to display an alert and prevent the window from closing. On AppKit we can use the windowShouldClose delegate method of NSWindowDelegate. Unfortnuately this is not available on Catalyst. Did someone found a way on Catalyst to prevent a window from closing? Maybe there is a way to expose the AppKit NSWindowDelegate object? Thank you
2
0
1.8k
Oct ’22
Settings bundle with string catalog
Is it possible to use a string catalog to localize a settings bundle? Currently, to localize a Settings.bundle, we need to create a folder for each language with a single strings file inside. For example: Settings.bundle en.lproj > Root.strings fr.lproj > Root.strings de.lproj > Root.strings ... Any way to convert that to a string catalog? Thank you
2
2
2k
Jan ’24
Incorrect height of iPad floating keyboard
I'm using the following code to get the height of the keyboard: class ViewController: UIViewController {     override func viewDidLoad() {         super.viewDidLoad()         NotificationCenter.default.addObserver(             self,             selector: #selector(keyboardHeight),             name: UIResponder.keyboardDidChangeFrameNotification,             object: nil         )     }     @objc private func keyboardHeight(notification: Notification) {         guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return }         print("==> keyboardFrameEndUserInfoKey height: \(keyboardRect.size.height)")     } } This code on iPad work correctly when the keyboard is normal but it does not work when the keyboard is floating. After the user tap on a text field, the keyboard appear and the keyboardDidChangeFrameNotification notification is called. If the keyboard is floating then the first time we get a wrong height of 362. If the user then manually move somewhere the floating keyboard the notification is called again and the correct value of 308 is returned. It is a bug or I miss something? I need to be able to get the correct height the first time the keyboard appear. This is happening on iOS 13 and iOS 14. Any idea?
1
1
1.3k
Jul ’21
supplementarySidebarTrackingSeparatorItemIdentifier
I'm developing an iOS 14 Catalyst app and I'm trying to setup the window toolbar. I created a NSToolbar and assigned to the scene window titlebar property. var toolbarDelegate = ToolbarDelegate() func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { #if targetEnvironment(macCatalyst) guard let windowScene = scene as? UIWindowScene else { return } let toolbar = NSToolbar(identifier: "main") toolbar.delegate = toolbarDelegate toolbar.displayMode = .iconOnly if let titlebar = windowScene.titlebar { titlebar.toolbar = toolbar titlebar.toolbarStyle = .unified titlebar.titleVisibility = .hidden } #endif } I then assigned some items to the toolbar via the toolbarDefaultItemIdentifiers delegate method. func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { let identifiers: [NSToolbarItem.Identifier] = [ .toggleSidebar, .print, .flexibleSpace, .print ] return identifiers } This work as expected. Now, let's say that I want to align some items with the edges of the supplementary column. I found that there is an NSToolbarItem named supplementarySidebarTrackingSeparatorItemIdentifier. This item appears to allow us to align items with the supplementary column. If I do this: func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { let identifiers: [NSToolbarItem.Identifier] = [ .toggleSidebar, .flexibleSpace, .print, .supplementarySidebarTrackingSeparatorItemIdentifier, .print, .flexibleSpace, .print ] return identifiers } I got the following result which is exactly what I want to achieve (the items are aligned with the supplementary column): But there are some issues. As you can see from the above image for some reason the background color of the toolbar on top of the supplementary column become white. But it's worse. If I resize the window the background instantly become gray: If I then scroll the content of the supplementary column the toolbar become white again. Another issue is that If I collapse the primary column the toolbar on top of the supplementary column loose the right separator line. Why? I tried to search some info online but if I try to search for supplementarySidebarTrackingSeparatorItemIdentifier I got only 5 results! One of these is Apple's official documentation page, which does not contain any info about the behaviour of this item: Apple documentation about supplementarySidebarTrackingSeparatorItemIdentifier At this point I wonder if this item is ready to be used in real apps. Someone has experience using the supplementarySidebarTrackingSeparatorItemIdentifier item? There is a way to align toolbar items with the supplementary column without having the above described issues? (different toolbar background color, missing toolbar separator line) Thank you
1
0
1.5k
Aug ’24
Preprocessor, variables and "Will never be executed"
I need to set the value of a variable according to a preprocessor rule, like in the example below. var doSomething = false #if targetEnvironment(macCatalyst) doSomething = true #endif if doSomething { print("Execute!") } If I build the code for an iOS simulator, Xcode will generate a "Will never be executed" alert at the print("Execute!") line. This make sense because preprocessor rules are evaluated before compilation and therefore the code above, when the target is an iOS simulator, corresponds to: var doSomething = false if doSomething { print("Execute!") } I just want to know if there is any advices for handling cases like that. Ideally, I would like to avoid using the preprocessor condition for every statement, like so: #if targetEnvironment(macCatalyst) print("Execute!") #endif but rely on a variable like the original example. I would also prefer to avoid completely disabling in Xcode the display of "Will never be executed" warnings for all source codes. Is there a way to set the "doSomething" variable so that Xcode doesn't display the warning in a case like that? Thank you
1
0
1.1k
Mar ’22
UITextField with isSecureTextEntry in Catalyst display an empty box
Hi, In a Mac Catalyst app, I need to allow the user insert a passcode using a UITextField. The field is used to insert a one time passcode and I want to keep the content hidden. For this reason I set the isSecureTextEntry property to true. passcodeTextField.isSecureTextEntry = true By doing this, a button to allow the user to pick a password from the keychain is displayed: This option in my case should not appear because the password is a one time password that change every time. For that reason I set the textContentType to oneTimeCode. passcodeTextField.textContentType = .oneTimeCode This actually removes the password button, but introduce something weird. If the user type something and then delete everything, a big empty box appear under the field: I have no idea what this box is and why it appears. Does anyone know why it appears and how I can remove it? Thank you
1
1
852
Apr ’25
Pending purchases in StoreKit 2
Hi, I'm looking for a way to get the list of pending purchases, i.e. the purchases made when the "Ask to buy" feature is enabled and which have yet to be approved. I need this in order to update the UI of my store and disable the possibility to buy products when they are pending for approval. I tried to look into Transaction.all but pending transactions seems to be missing. How can we get the list of pending purchases? Thank you
1
0
2.3k
May ’22
Scale of image generated with MKMapSnapshotter
Hi, I need to generate the image of a map at a specific resolution. I tried to use the following code: let options = MKMapSnapshotter.Options() options.size = CGSize(width: 300, height: 200) options.scale = 1.0 options.mapRect = mapRect let mapSnapshotter = MKMapSnapshotter(options: options) if let snapshot = try? await mapSnapshotter.start() { let image = snapshot.image } Since I specified the options.scale to be 1 I expect the image resolution to be exactly 300x200 pixel (and with a scale of 1). Unfortunately the resulting image has a scale factor of 3 (on an iPhone) and the actual resolution is 900x600 pixel. I also tried, instead of using the scale option, to set the traitCollection option, like this: options.traitCollection = UITraitCollection(displayScale: 1.0) but I still get a 3x scale image with a resolution of 900x600. Why is the scale option ignored? I miss something? Thank you
1
2
1.5k
Jul ’22
UILabel rendered in cgContext is blurry on Mac Catalyst
Hi, The following code allow to build an image from an UILabel: let label = UILabel() label.text = "test content" label.backgroundColor = .white label.layer.cornerRadius = 10 label.layer.masksToBounds = true label.sizeToFit() let format = UIGraphicsImageRendererFormat() format.scale = 5 let renderer = UIGraphicsImageRenderer(bounds: label.bounds, format:format) let image: UIImage? = renderer.image { rendererContext in label.layer.render(in: rendererContext.cgContext) } This works perfectly on iOS but on Mac Catalyst the label text is very blurry as you can see in the image below. Both images are created with the same exact code and have the exact same resolution of 460x103. On top the iOS version and on bottom the Mac Catalyst version. Note that not all of the image is blurry, but only the text. In the code I set a corner radius of 10 and you can see that the corner is rendered with an high resolution, like the iOS version. It's just the text that for some reason is blurry. It's like if the label text is rendered with a scale of 1 and then scaled up. Someone know why? There is something I can do to improve the rendering of the text? Thank you
1
0
1.3k
May ’22
Table cell focus after selection
Hi, I have a controller with a UITableView. If the user, on an iPad with a keyboard or on the Mac, press the tab key, the first cell is focused showing a border. The user can then move the focus using the keyboard arrows. That's ok. The problem is that the cell is focused also when the cell is selected manually, i.e. by tapping on it. It is possibile to keep the cell focus feature when the user use the tab key, but stop focusing the cell when it's activated directly by tapping on it? Thank you
1
0
1.3k
May ’22