Skip to content

Commit

Permalink
[Foundation] Add NSProxy stub in order to workaround bug 59247 (#2693)
Browse files Browse the repository at this point in the history
https://bugzilla.xamarin.com/show_bug.cgi?id=59247

We need to have a better solution that removes all what NSProxy does not responds to.
Right now this works because NSObject implements NSObject protocol just like NSProxy, but
NSProxy responds to far less selectors hence doing it internal so it is not a breaking change
when we provide the correct fix.

* Keep NSProxy around and avoid XML linker description

We need to keep NSProxy (avoid linking it) if WKNavigationDelegate or IWKNavigationDelegate
is used. We know WKWebView will be there and can hold a reference to it.
  • Loading branch information
dalexsoto authored and spouliot committed Sep 14, 2017
1 parent 1e8c5de commit 46c6a7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Foundation/NSProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// NSProxy.cs
//
// Authors:
// Alex Soto <alexsoto@microsoft.com>
//
// Copyright 2017 Xamarin Inc. All rights reserved.
//

// HACK:
// Yep this is just a hack to workaround https://bugzilla.xamarin.com/show_bug.cgi?id=59247
// we need to have a better solution that removes all what NSProxy does not responds to.
// Right now this works because NSObject implements NSObject protocol just like NSProxy, but
// NSProxy responds to far less selectors hence doing it internal so it is not a breaking change
// when we provide the correct fix.

using System;
using System.ComponentModel;
using XamCore.Foundation;
using XamCore.ObjCRuntime;

namespace XamCore.Foundation {
[EditorBrowsable (EditorBrowsableState.Never)]
[Register ("NSProxy", true)]
internal abstract class NSProxy : NSObject {
}
}

namespace XamCore.WebKit {
// We need to keep NSProxy (avoid linking it) if WKNavigationDelegate or IWKNavigationDelegate
// is used. Unfortunately [Preserve] can't help us here because we do not generate partial
// interfaces rigth now, so we know WKWebView will be there and can hold a reference to it.
public partial class WKWebView {
[Preserve (Conditional = true)]
static Type hack = typeof (NSProxy);
}
}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ FOUNDATION_SOURCES = \
Foundation/NSPortMessage.cs \
Foundation/NSPredicate.cs \
Foundation/NSPropertyListSerialization.cs \
Foundation/NSProxy.cs \
Foundation/NSRunLoop.cs \
Foundation/NSScriptCommandDescription.cs \
Foundation/NSScriptCommandArgumentDescription.cs \
Expand Down

0 comments on commit 46c6a7d

Please sign in to comment.