I am building an iOS app using MonoTouch and attempting to implement a custom NSUrlProtocol.
When I register my own protocol implementation, I get the following error:
WebKit discarded an uncaught exception in the
webView:decidePolicyForNavigationAction:request:frame:decisionListener:
delegate: * -canInitWithRequest: only
defined for abstract class. Define
-[Foo.Network.NetworkServices+TestProtocol canInitWithRequest:]!
Any thoughts on what could be causing this?
Here is the code:
//Registering the protocol
NSUrlProtocol.RegisterClass(new Class(typeof(TestProtocol)));
public class TestProtocol : NSUrlProtocol
{
public TestProtocol ()
{
this.Client = new TestProtocolClient();
}
public override bool CanInitWithRequest (NSUrlRequest request)
{
return true;
}
}
public class TestProtocolClient : NSUrlProtocolClient
{
public override void DataLoaded (NSUrlProtocol protocol, NSData data)
{
}
public override void FailedWithError (NSUrlProtocol protocol, NSError error)
{
}
public override void ReceivedResponse (NSUrlProtocol protocol, NSUrlResponse response, NSUrlCacheStoragePolicy policy)
{
}
public override void Redirected (NSUrlProtocol protocol, NSUrlRequest redirectedToEequest, NSUrlResponse redirectResponse)
{
}
public override void CachedResponseIsValid (NSUrlProtocol protocol, NSCachedUrlResponse cachedResponse)
{
}
public override void FinishedLoading (NSUrlProtocol protocol)
{
}
public override void ReceivedAuthenticationChallenge (NSUrlProtocol protocol, NSUrlAuthenticationChallenge challenge)
{
}
public override void CancelledAuthenticationChallenge (NSUrlProtocol protocol, NSUrlAuthenticationChallenge challenge)
{
}
}
The NSUrlProtocol support in MonoTouch is currently broken.
It will be fixed in the next beta release (MonoTouch 5.3.3). There is also a sample available to show how it works (but it will obviously not work until MonoTouch 5.3.3 is out).
Xamarin’s support can usually give you preview builds if it’s an urgent matter.