我正在使用 MonoTouch 构建 iOS 应用程序并尝试实现自定义 NSUrlProtocol。
当我注册自己的协议实现时,出现以下错误:
WebKit 丢弃了 webView:decidePolicyForNavigationAction:request:frame:decisionListener:delegate: * -canInitWithRequest: 仅为抽象类定义的未捕获异常。定义-[Foo.Network.NetworkServices+TestProtocol canInitWithRequest:]!
关于可能导致这种情况的任何想法?
这是代码:
//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)
{
}
}