iOS 9:崩溃 -[_NSXPCDistantObject methodSignatureForSelector:]

iOS 9: Crash on -[_NSXPCDistantObject methodSignatureForSelector:]

我遇到了一个奇怪的错误:

Fatal Exception: NSInvalidArgumentException *** -[_NSXPCDistantObject methodSignatureForSelector:]: No protocol has been set on connection connection to service named com.apple.nsurlsessiond"

这个问题似乎只在 iOS 9 上发生。根据堆栈跟踪,错误是由对 -[UIApplication _sendWillEnterForegroundCallbacks].

的调用触发的
Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 6485512008 __exceptionPreprocess
1  libobjc.A.dylib                6833323904 objc_exception_throw
2  CoreFoundation                 6485511824 -[NSException initWithCoder:]
3  Foundation                     6500536092 -[_NSXPCDistantObject methodSignatureForSelector:]
4  CoreFoundation                 6485526892 ___forwarding___
5  CoreFoundation                 6484495532 _CF_forwarding_prep_0
6  CoreFoundation                 6485141004 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
7  CoreFoundation                 6485138988 _CFXRegistrationPost
8  CoreFoundation                 6485138348 ___CFXNotificationPost_block_invoke
9  CoreFoundation                 6485554212 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
10 CoreFoundation                 6484354836 _CFXNotificationPost
11 Foundation                     6500543948 -[NSNotificationCenter postNotificationName:object:userInfo:]
12 UIKit                          6577878356 -[UIApplication _sendWillEnterForegroundCallbacks]
   continues ... 

所以看起来当应用程序进入前台时,一些注册的观察者试图通过 RPC 重新连接 nsurlsessiond 但失败了?我使用 NSURLSession 进行后台传输会话,但我无法重现它,所以我不确定它是否相关。

有人见过这个问题吗?我能做些什么来解决它吗?

似乎之前订阅了 UIApplicationWillEnterForeground 通知的东西在没有取消订阅的情况下被释放,或者预期的界面不存在。

我会检查您的应用程序已订阅该通知的任何地方,并确保它正确取消订阅,并确保引用的方法得到实施。

methodSignatureForSelector 失败表示 NSNotificationCenter 想要调用的通知方法未实现。可能是缺少方法,或输入错误。

看起来像是 iOS 中描述的错误:https://forums.developer.apple.com/thread/45651#140745

AFAICT this crash is caused by NSURLSession’s background session support. This passes work to its daemon (nsurlsessiond) using NSXPCConnection (not part of the iOS SDK, but public API on OS X, so you can read up about it there). NSXPCConnection has the notion of interrupted connections, that is, the IPC connection between the client and the server has torn but can be re-established. NSURLSession’s background session support, like all NSXPCConnection clients, must handle these interruptions as a matter of course. Alas, there’s a bug in the way it does that. This bug is a race condition that manifest itself as this crash. We hope to fix this in a future OS release but I can’t share any concrete details.