Link follows when using UIWebView+AFNetworking

2019-05-06 04:30发布

I'm trying out AFNetworking 2.0+'s new UIKit+AFNetworking extension for UIWebView, loadRequest:progress:success:failure:. So far so good, but after the initial request is made, additional requests caused by user interaction falls back to the built-in loadRequest: of plain UIWebView.

I'd much prefer that all requests went through the AFNetworking improved one. Preliminary, I'm thinking I should override as much as possible by returning NO in shouldStartLoadWithRequest and call loadRequest:progress:success:failure: manually, but it seems a little heavy-handed.

Is this the intended way or am I missing something in the documentation?

1条回答
叛逆
2楼-- · 2019-05-06 04:38

It might be worth reading through the implementation of UIWebView+AFNetworking (it's only 120 lines).

What you're looking for isn't implemented by this class. Furthermore, since UIWebView+AFNetworking is a category, which extends an existing object, implementing it in this class would require setting the UIWebView's delegate to itself, which would stop you from responding to any of its delegate methods.

Your discussed possible approach - returning NO to -[id<UIWebViewDelegate> webView:shouldStartLoadWithRequest:navigationType:] and then redirecting to use the method you want is the right approach. (You'll need to return YES for your own request.)

查看更多
登录 后发表回答