Register a custom NSUrlProtocol in MonoTouch

I am building an iOS application using MonoTouch and trying to implement a custom NSUrlProtocol.

When I register my own protocol implementation, I get the following error:

WebKit has thrown the uncaught exception in WebView: decidePolicyForNavigationAction: request: frame: decisionListener: delegate: * -canInitWithRequest: only defined for the abstract class. define - [Foo.Network.NetworkServices + TestProtocol canInitWithRequest:]!

Any thoughts on what might 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)
    {
    }
}
+3
source share
1 answer

MonoTouch's NSUrlProtocol support is currently broken.

- (MonoTouch 5.3.3). sample, , ( , , MonoTouch 5.3.3).

Xamarin support , .

+3

All Articles