handleEventsForBackgroundURLSession never called when a downloadTask finished

前端 未结 2 828
渐次进展
渐次进展 2021-02-20 17:15

I am using AFURLSessionManager, and set the manager as a singleton instance.

- (AFURLSessionManager *)backgroundSession
{
    static AFURLSessionManager *backgro         


        
2条回答
  •  感情败类
    2021-02-20 17:39

    You probably have figured this out already but anyway, the exact same thing has happened to me while writing some test code to play with the background transfer service APIs (without AFNetworking). The solution was simply to change the identifier string for my background session configuration. Somehow the one I was using got bugged and the system wouldn't trigger the handleEventsForBackgroundURLSession callback. And not even restarting the device fixes it... however just changing the identifier does.

    My theory is that my code created multiple instances of NSURLSession with the same configuration, which Apple clearly advices against (they say in the documentation that it has an undefined behavior if you do). I was obtaining the NSURLSessionConfiguration in the view controller's viewDidLoad method without a dispatch_once block, so it's certainly plausible that that happened.

提交回复
热议问题