Apple Maps: MKMapView and UITapGestureRecognizer - cannot detect taps on the map. #4671
-
Hi, I've successfully been using the features of Apple Maps for some time in my KMP app. For several reasons I would like to react to taps on the map - that is, not react to taps on annotation markers (which is easy) but to taps anywhere on the map. Unfortunately this does not seem to be possible in KMP, no matter what strategy I try. In Swift this is fairly easy to do and I have followed the same route for KMP. Here is a snippet of my code, just showing the relevant sections:
The problem lies in the recognizer and registering of the name. It is just not recognised and produces the following error as soon as the map is tapped:
There seems to be some disconnect between Kotlin and Objective C when it comes to the name and thus it crashes before the function handleTap() is called. I have tried many different ways to get this working but to no avail. The only thing I haven't tried is using cinterops and do part of it in C . In previous attempts for other things I've not had much joy in getting Kotlin -> C to work, so I didn't really want to go down this route until asking to see if someone might point out a possible problem with my code or suggest the correct way to go about this. Personally, I'd rather do away with detecting taps in the native code and just attach a listener on the Common side, but sadly KMP Compose does not allow gestures to be filtered - you either get all or none sent to the map view. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, it seems like you don't have an inheritance clause (like |
Beta Was this translation helpful? Give feedback.
Hi, it seems like you don't have an inheritance clause (like
: NSObject()
, so your class is not an ObjC class. In runtime you simply try to call a selector on a pointer representing a Kotlin object, which has different internal structure and doesn't really know anything about ObjC runtime.