Fixed potential KVO crasher for URL Session Task delegates by 0xced · Pull Request #3718 · AFNetworking/AFNetworking
added 2 commits
September 30, 2016 23:32Adding self as observer in init and removing self as observer in dealloc is the best way to ensure a proper KVO implementation.
The dispatching on main thread was introduced in 920e266 in order to fix #2053. It was not a proper fix but rather a lucky coincidence. This kind of KVO error must be fixed by ensuring that observer are properly registered and unregistered, not by dispatching some random method on the main thread. It is very important not to dispatch async session invalidation code because it is called in unit tests from the `tearDown` method. At that point, there’s no active runloop, so the session invalidation would not happen immediately but when running the next asynchronous unit test, i.e. when the `waitForExpectationsWithCommonTimeoutUsingHandler:` method is called. This commit, in conjunction with d869571 fixes #3710.
kcharwood
changed the title
Fix potential KVO crasher
Fixed potential KVO crasher for URL Session Task delegates
0xced
deleted the
fix-potential-KVO-crasher
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters