Repository navigation
Mac/iOS: register delegate protocols when the runtime doesn't know them - #92
Merged
Merged
Conversation
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
force-pushed
the
fix/ios26-protocol-registration
branch
from
October 12, 2026 05:26
d23c95b to
b91b08a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #90
Problem
Our managed delegate classes (
WKScriptMessageHandler,WKNavigationDelegate,ASWebAuthenticationPresentationContextProviding) only got their protocol ifobjc_getProtocolfound it.objc_getProtocolonly 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/IWKNavigationDelegatemakes the app binary register those protocols.Fix
New
NSObject.AddProtocol(classHandle, name, methods)helper:NSObjectand has descriptions for the methods we implement, e.g. the requireduserContentController:didReceiveScriptMessage:. The runtime checks conformance by name, so WebKit accepts it.Testing
invokeCSharpActionmessage received. The protocol is found there, so the simulator doesn't reproduce WKWebView Binding for DidReceiveScriptMessage in iOS 26 needs updating #90.protocol_getMethodDescriptionreturnsv@:@@, and messages still arrive.🤖 Generated with Claude Code