Posts

Post not yet marked as solved
2 Replies
1.2k Views
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
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
1 Replies
3k Views
Hi, I just discovered a weird bug with UITextView on iOS 16 beta 4. For some reason now, when the scrolling is disabled, the intrinsic content size of the text view is considering the line spacing even when the textview is empty. For example, in the below code we are setting a big lineSpacing of 50 to the text view typingAttributes attribute. class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! { didSet { //Let's set the textView typingAttributes with a lineSpacing of 50. var attributes = [NSAttributedString.Key: Any]() let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 50 attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle attributes[NSAttributedString.Key.font] = UIFont.preferredFont(forTextStyle: .body) textView.typingAttributes = attributes } } } On previous iOS versions, everyting it's ok and the line spacing is added only when there are more than one line (see below image). However, on iOS 16 beta 4, the line spacing is added also when the content is empty (see below image on the left). A soon as we type something the height collapse to the correct height (see below image in the center). Is this a new expected behavior or a bug? If it is a bug, someone has found a temporary fix for that? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
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
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
1 Replies
1.3k Views
Hi, I have a controller where the user can search for map locations or points of interest by typing inside a search box. To retrieve the list of results I set the queryFragment parameter of a MKLocalSearchCompleter with the search content. This correctly gives me back a list of MKLocalSearchCompletion of locations and points of interest. When a user tap on one of this locations, I need to load the coordinates. In order to do that I do a MKLocalSearch passing the selected MKLocalSearchCompletion, like so: let item = items[indexPath.row] let request = MKLocalSearch.Request(completion: item) let search = MKLocalSearch(request: request) search.start { (response, error) in //Do stuff with the result. //For some specific items I receive an MKErrorDomain 4 error. } This works most of the time, but for some specific items the MKLocalSearch call return the error: Error Domain=MKErrorDomain Code=4 "(null)" UserInfo={MKErrorGEOError=-8} This error correspond to "placemarkNotFound", ie MapKit is not able to find a placemark for the specific MKLocalSearchCompletion. I just don't understant why this should be the case. The MKLocalSearchCompletion is returned by MapKit. If it is returned by MapKit then a corresponding placemark should exist, right? Why then is MapKit unable to perform a local search on it? The problem now is that I present the user with a list of completions returned by MapKit but tapping some of them nothing happens because I cannot determine their respective coordinates. Why is the search failing sometime? I miss something? Thank you
Posted
by DaleOne.
Last updated
.
Post marked as solved
1 Replies
1.1k Views
Hi, I want to set the glyphImage property for an annotation view (MKMarkerAnnotationView) of a cluster annotation (MKClusterAnnotation). Using the below code, inside the marker I get, instead of the glyphImage, the standard cluster number. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if let cluster = annotation as? MKClusterAnnotation { var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "GroupMapClusterAnnotation") if annotationView == nil { annotationView = MKMarkerAnnotationView(annotation: cluster, reuseIdentifier: "GroupMapClusterAnnotation") } (annotationView as? MKMarkerAnnotationView)?.glyphImage = UIImage(systemName: "star.fill") return annotationView } } I think that the problem is that if you keep the glyphText property empty, MapKit automatically set it with the number of the cluster member annotations. The documentation for glyphImage says: Use this property or the glyphText property to specify the marker balloon content. If you specify both an image and text, MapKit displays the text. So, MapKit is setting glyphText with a value an therefore the glyphImage property is ignored. How can we use the glyphImage property for a cluster annotation? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
9 Replies
20k Views
Hi!I currently developing a mobile website and found that Safari on iOS has some problems setting the focus on inputs when they are inside an iframe.When in a page you have many inputs you can tap on a field and then use the next / previous buttons on the keyboard to navigate between the fields. When the focus move to another input Safari scroll automatically the page centering the field in the page. This is great and works well.The problem is when the fields are inside a page of an iframe. In this case when you change focus from one field to another Safari has some kind of issue; the page “bounce” and the focused field is not centered in the page.I have made a video of a simple page that has this issue. In the first part of the video the page without the iframe is loaded and the focus works correctly. In the second part the page with the iframe is loaded and the issue is visible.http://www.dale1.ch/documents/safari_iframe_focus_issue.movThe code of the first page (testinput.html) where the focus is correctly handled is this:<!DOCTYPE html> <html> <head> <title>Test input</title> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" /> </head> <body> <div><span>Input 1: </span><input type="text" tabindex="1" /></div> <div><span>Input 2: </span><input type="text" tabindex="2" /></div> <div><span>Input 3: </span><input type="text" tabindex="3" /></div> <div><span>Input 4: </span><input type="text" tabindex="4" /></div> <div><span>Input 5: </span><input type="text" tabindex="5" /></div> <div><span>Input 6: </span><input type="text" tabindex="6" /></div> <div><span>Input 7: </span><input type="text" tabindex="7" /></div> <div><span>Input 8: </span><input type="text" tabindex="8" /></div> <div><span>Input 9: </span><input type="text" tabindex="9" /></div> <div><span>Input 10: </span><input type="text" tabindex="10" /></div> <div><span>Input 11: </span><input type="text" tabindex="11" /></div> <div><span>Input 12: </span><input type="text" tabindex="12" /></div> <div><span>Input 13: </span><input type="text" tabindex="13" /></div> <div><span>Input 14: </span><input type="text" tabindex="14" /></div> <div><span>Input 15: </span><input type="text" tabindex="15" /></div> <div><span>Input 16: </span><input type="text" tabindex="16" /></div> <div><span>Input 17: </span><input type="text" tabindex="17" /></div> <div><span>Input 18: </span><input type="text" tabindex="18" /></div> <div><span>Input 19: </span><input type="text" tabindex="19" /></div> <div><span>Input 20: </span><input type="text" tabindex="20" /></div> <div><span>Input 21: </span><input type="text" tabindex="21" /></div> <div><span>Input 22: </span><input type="text" tabindex="22" /></div> <div><span>Input 23: </span><input type="text" tabindex="23" /></div> <div><span>Input 24: </span><input type="text" tabindex="24" /></div> <div><span>Input 25: </span><input type="text" tabindex="25" /></div> <div><span>Input 26: </span><input type="text" tabindex="26" /></div> <div><span>Input 27: </span><input type="text" tabindex="27" /></div> <div><span>Input 28: </span><input type="text" tabindex="28" /></div> </body> </html>This is the code of the page that has the issue (testinput_iframe.html):<!DOCTYPE html> <html> <head> <title>Test input</title> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" /> </head> <body> <iframe src="/testinput.html" /> </body> </html>The issue is present in Safari on the iPhone, iPad and the xCode Simulator from version 8.4 to version 9.2.Someone know if this is a bug? There is way to fix it in css or javascript?Thanks and sorry for my english! 😉
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
1 Replies
931 Views
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
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
1k Views
Hi, I'm trying to define the style of an UIButton using UIButton.Configuration in a Mac Catalyst app. I was able to configure the component as I want except one thing. I want to change the style of the button when the window is not active. The default filled style automatically do this. For example below you can see a button configured with UIButton.Configuration.filled(). If the window become inactive (for example by activating another application) the color of the button change, like so: Now, If I configure a button with this configuration: var configuration = UIButton.Configuration.plain() configuration.background.strokeColor = .gray configuration.baseForegroundColor = .red configuration.baseBackgroundColor = .clear the button display with this configuration when the window is active: but also when it's not active: I want to change the text color from red to gray when the window is not active. Someone know how to do it? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
1 Replies
1k Views
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
Posted
by DaleOne.
Last updated
.
Post marked as solved
1 Replies
1.2k Views
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
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
623 Views
Hi, I'm starting using StoreKit 2 and I have some questions regarding transactions. To check which non-consumable in-app purchases the user has purchased, immediately after starting the app I look at Transaction.currentEntitlements. That's working fine, but I have some questions about it. Question 1: What happens if the user is not connected to the internet? Will Transaction.currentEntitlements still return data? Question 2: What happens if the user sign out from the AppStore? Will Transaction.currentEntitlements be empty? Question 3: What happens if the user sign in AppStore with different credentials? Transaction.currentEntitlements will return the transaction of the new AppStore user? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
615 Views
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
Posted
by DaleOne.
Last updated
.
Post marked as solved
1 Replies
829 Views
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
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
724 Views
Hi, If I generate an image from a symbol the resulting image is surrounded by some margins. For example this code: let image = UIImage(systemName: "suit.heart") will generate this image: As you can see there are some margins around the content. There is a way to build an image cropped to the actual content, like showed in the below example? Thank you
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
3 Replies
747 Views
Hi, I need to understand inside an override of UIBarButtonItem what is the systemItem of the button (done, add, trash, search, ...). Unfortunately at the moment the only method I found is to inspect the content of self.description (see below), but this solution, as well as being ugly, is very fragile because we can't be sure that the description will be the same also on future version of iOS / Swift. Someone know a better way to check for systemItem inside an UIBarButtonItem override class? Thank you class BarButtonItem: UIBarButtonItem {     override func awakeFromNib() {         super.awakeFromNib()         print(self.description)     } } <MyApp.BarButtonItem: 0x7fadbcacbea0> systemItem=Trash
Posted
by DaleOne.
Last updated
.