Skip to content

Mac/iOS: register delegate protocols when the runtime doesn't know them - #92

Merged
maxkatz6 merged 1 commit into
mainfrom
fix/ios26-protocol-registration
Oct 12, 2026
Merged

maxkatz6 merged 1 commit into
mainfrom
fix/ios26-protocol-registration

Conversation

@maxkatz6

@maxkatz6 maxkatz6 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #90

Problem

Our managed delegate classes (WKScriptMessageHandler, WKNavigationDelegate, ASWebAuthenticationPresentationContextProviding) only got their protocol if objc_getProtocol found it. objc_getProtocol only returns protocols that some loaded image references. When it returned null, the class silently didn't conform, and per #90 WebKit crashes on iOS 26.

The workaround in the issue fits this: declaring a Xamarin class that implements IWKScriptMessageHandler/IWKNavigationDelegate makes the app binary register those protocols.

Fix

New NSObject.AddProtocol(classHandle, name, methods) helper:

  • If the runtime knows the protocol, add it as before.
  • Otherwise, register a protocol with the same name. It conforms to NSObject and has descriptions for the methods we implement, e.g. the required userContentController:didReceiveScriptMessage:. The runtime checks conformance by name, so WebKit accepts it.

Testing

🤖 Generated with Claude Code

objc_getProtocol only returns protocols that some loaded image references.
When it returned null, our managed delegate classes silently didn't conform
to WKScriptMessageHandler, WKNavigationDelegate and
ASWebAuthenticationPresentationContextProviding, which breaks WebKit on iOS 26.

Now, if the protocol is missing, we register one with the same name and the
method descriptions we implement. The runtime checks conformance by name.

Fixes #90

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maxkatz6
maxkatz6 force-pushed the fix/ios26-protocol-registration branch from d23c95b to b91b08a Compare October 12, 2026 05:26
@maxkatz6
maxkatz6 merged commit e832988 into main Oct 12, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WKWebView Binding for DidReceiveScriptMessage in iOS 26 needs updating

1 participant