Xamarin-macios: macOS: cannot instantiate MKLocalSearchCompleter

Created on 2 Apr 2020  路  7Comments  路  Source: xamarin/xamarin-macios

Steps to Reproduce

var searchCompleter = new MKLocalSearchCompleter();

Expected Behavior

Compiles (it does compile on iOS)

Actual Behavior

Does not compile
Perhaps caused by this line: https://github.com/xamarin/xamarin-macios/blob/63d092d5268a53acc601f54f58b2db96c7e169f6/src/mapkit.cs#L1901
Is there no way to create a MKLocalSearchCompleter on macOS?

bug macOS

Most helpful comment

Appears to work - thanks for the swift help! :)

All 7 comments

It works on macOS today in Xcode. Looks like a binding mistake or API break on Apple's side.

Do you need a work around @tipa for this?

Not sure if I understand correctly...
As you can see in the screenshot, the Xamarin bindings don't offer a default constructor:
Screenshot 2020-04-03 at 22 30 54
However I think there should be one (from https://developer.apple.com/documentation/mapkit/mklocalsearchcompleter):
image
A work around would be great until it is fixed in the Xamarin bindings :)

I was just pointing out the comment around the attribute:

#if MONOMAC || XAMCORE_3_0 // Avoid breaking change in iOS
    [DisableDefaultCtor]
#endif

Suggests Apple broke some API at some point.

Let me get you a manual binding workaround shortly..

Give this a shot:

        public class MKLocalSearchCompleterExtensions
    {
        static readonly System.IntPtr AllocSelector = ObjCRuntime.Selector.GetHandle ("alloc");
        static readonly System.IntPtr InitSelector = ObjCRuntime.Selector.GetHandle ("init");

        [DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
        public extern static System.IntPtr IntPtr_objc_msgSend (System.IntPtr receiver, System.IntPtr selector);

        public static MKLocalSearchCompleter Create ()
        {
            System.IntPtr handle = IntPtr_objc_msgSend (ObjCRuntime.Class.GetHandle (typeof(MKLocalSearchCompleter)), AllocSelector);
            handle = IntPtr_objc_msgSend (handle, InitSelector);
            return ObjCRuntime.Runtime.GetNSObject<MKLocalSearchCompleter> (handle);
        }
    }

Appears to work - thanks for the swift help! :)

Any timeline when this will be shipped and I can remove the workaround @chamons? :)

$ git branch --all  --contains c0b8036d3b3c598c22abf9650011e0f9b6c1827d | grep d16-
  remotes/origin/d16-8

The fix is in our d16-8 release branch, currently in Beta.

Was this page helpful?
0 / 5 - 0 ratings