Link follows when using UIWebView+AFNetworking

半世苍凉 提交于 2019-12-22 08:59:31

问题


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:


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.)



来源:https://stackoverflow.com/questions/19384418/link-follows-when-using-uiwebviewafnetworking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!