Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有好的方案,把URLSessionDataDelegate更多的协议实现暴露出来 #1620

Merged
merged 6 commits into from
Mar 4, 2021

Conversation

wangshuaiguo
Copy link
Contributor

#1619

尝试一种方案。把URLSessionDataDelegate的其他协议方法,转发给业务方定制化处理

@onevcat
Copy link
Owner

onevcat commented Feb 8, 2021

我可能更倾向于把 SessionDelegate 写成 open 然后通过 subclass 的方式来实现自定义逻辑。
当然,这个 PR 里的实现也是一种办法。我考虑一下哪种会更好。



/// You could set the extra handler before a downloading task starts.
public weak var extraSessionDelegateHandler:URLSessionDataDelegate? {
Copy link
Owner

@onevcat onevcat Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public weak var extraSessionDelegateHandler:URLSessionDataDelegate? {
public var extraSessionDelegateHandler:URLSessionDataDelegate? {

For a getter/setter, there should be no need to mark it as weak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,多谢!

func getExtraHandler() -> URLSessionDataDelegate? {
return extraHandler
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to remove these methods and make extraHandler to internal, so we can just use the property without this boilerplate method calling.

2、getter/setter方法无需weak标记
@onevcat onevcat merged commit ba51e9d into onevcat:master Mar 4, 2021
@onevcat
Copy link
Owner

onevcat commented Mar 4, 2021

Nice! Thank you.

@onevcat
Copy link
Owner

onevcat commented Mar 9, 2021

It seems that these changes cause an error while loading.

2021-03-09 11:51:23.423663+0900 Kingfisher-Demo[44705:9436274] 44705: CFNetwork internal error (0xc01a:/Library/Caches/com.apple.xbs/Sources/CFNetwork_Sim/CFNetwork-1220.1/Loading/Connection/Loader Side/URLConnectionLoader.cpp:266)

I am not sure what is happening now, but reverting these changes can solve the issue. I am going to revert it and tag a patch version. I will also keep digging to see what is the problem/

onevcat added a commit that referenced this pull request Mar 9, 2021
This reverts commit ba51e9d, reversing
changes made to 3b6f450.
extraHandler?.urlSession?(session, dataTask: dataTask, didBecome: downloadTask)
}
func urlSession(_ session: URLSession, task: URLSessionTask, needNewBodyStream completionHandler: @escaping (InputStream?) -> Void) {
extraHandler?.urlSession?(session, task: task, needNewBodyStream: completionHandler)
Copy link

@dreampiggy dreampiggy Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you implements the URLSessionDelegate method with completionBlock, you MUST callback the handler, even if you don't have anything logic or nil extraHandler here.

Same as other delegate methods.

skoduricg pushed a commit to rentpath/Kingfisher that referenced this pull request Sep 24, 2021
有没有好的方案,把URLSessionDataDelegate更多的协议实现暴露出来
skoduricg pushed a commit to rentpath/Kingfisher that referenced this pull request Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants