Skip to content

Commit

Permalink
[uikit] Preserve method associated with `updateSearchResultsForSearch…
Browse files Browse the repository at this point in the history
…Controller:`. Fixes #5024 (#5027)

This method is called back from iOS (or tvOS) so there's no managed
reference pointing to it. However we know that if it's (private inner)
type is present it's because the callback (from native) is possible so
we can preserve the method conditionally (to the type presence).

#5024
  • Loading branch information
spouliot authored Oct 23, 2018
1 parent 74102bc commit b403da0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/UIKit/UISearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#if !WATCH

using System;
using Foundation;

namespace UIKit {

Expand All @@ -17,6 +18,8 @@ public __Xamarin_UISearchResultsUpdating (Action<UISearchController> cback)
this.cback = cback;
IsDirectBinding = false;
}

[Preserve (Conditional = true)] // called back from native, no direct managed reference (except on the type itself)
public override void UpdateSearchResultsForSearchController (UISearchController searchController)
{
cback (searchController);
Expand Down
14 changes: 14 additions & 0 deletions tests/linker/ios/link sdk/LinkSdkRegressionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,20 @@ public void TlsProvider_Apple ()
Assert.NotNull (provider, "provider");
Assert.That (provider.ID, Is.EqualTo (new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c")), "correct provider");
}

[Test]
public void Github5024 ()
{
TestRuntime.AssertXcodeVersion (6,0);
var sc = new UISearchController ((UIViewController) null);
sc.SetSearchResultsUpdater ((vc) => { });

var a = typeof (UISearchController).AssemblyQualifiedName;
var n = a.Replace ("UIKit.UISearchController", "UIKit.UISearchController+__Xamarin_UISearchResultsUpdating");
var t = Type.GetType (n);
Assert.NotNull (t, "private inner type");
Assert.IsNotNull (t.GetMethod ("UpdateSearchResultsForSearchController"), "preserved");
}
#endif // !__WATCHOS__

[Test]
Expand Down

0 comments on commit b403da0

Please sign in to comment.