Post

Replies

Boosts

Views

Created

MapKit crash on Catalyst after resizing the window
Hi, I am faced with a strange problem with a Catalyst app that uses MapKit. If the map is visible and I resize the window (causing the map the resize), sometime the app crashes with some Metal related error. Is this a know issue between MapKit and Catalyst? There is something I can do in order to prevent this crash? Below you can find the error message and a screenshot of the thread that caused the crash. Thank you -[MTLDebugDevice notifyExternalReferencesNonZeroOnDealloc:]:2951: failed assertion `The following Metal object is being destroyed while still required to be alive by the command buffer 0x7f96de27f600 (label: <no label set>): <MTLToolsObject: 0x7f96dde552e0> -> <BronzeMtlTexture: 0x7f96dc04c230> label = <none> textureType = MTLTextureType2D pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB width = 2372 height = 1668 depth = 1 arrayLength = 1 mipmapLevelCount = 1 sampleCount = 1 cpuCacheMode = MTLCPUCacheModeDefaultCache storageMode = MTLStorageModeManaged hazardTrackingMode = MTLHazardTrackingModeTracked resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeManaged MTLResourceHazardTrackingModeTracked usage = MTLTextureUsageShaderRead MTLTextureUsageRenderTarget shareable = 0 framebufferOnly = 0 purgeableState = MTLPurgeableStateNonVolatile swizzle = [MTLTextureSwizzleRed, MTLTextureSwizzleGreen, MTLTextureSwizzleBlue, MTLTextureSwizzleAlpha] isCompressed = 0 parentTexture = <null> parentRelativeLevel = 0 parentRelativeSlice = 0 buffer = <null> bufferOffset = 0 bufferBytesPerRow = 0 iosurface = 0x0 iosurfacePlane = 0 allowGPUOptimizedContents = YES'
6
2
4.6k
Jan ’22
Check for systemItem inside an UIBarButtonItem override
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
3
0
1.1k
Feb ’22
Popover from NSToolbarItem in Mac Catalyst app
Hi, Inside a Mac Catalyst app, I need to display a popover starting from an NSToolbarItem contained inside the app toolbar (like the Apple Maps Mac app does, see below image). In order to do that, when I press the button I need to find the toolbar item view and use it as popover anchor. How can I find the view or frame of an NSToolbarItem on Mac Catalyst? A property that could help me is the NSToolbarItem "view" property (NSView), but that property has been marked has unavailable in Mac Catalyst. Any idea? Thank you
3
3
1.9k
Feb ’22
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
853
Apr ’22
StoreKit 2 Transaction.currentEntitlements questions
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
0
3
873
May ’22
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
May ’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
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
May ’22
Mac Catalyst UIButton configuration when window is not active
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
0
0
1.2k
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
MKMarkerAnnotationView glyphImage for a cluster annotation
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
1
0
1.5k
Jun ’22
MKErrorDomain 4 when performing a MKLocalSearch with an MKLocalSearchCompletion
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
1
0
1.9k
Jun ’22