场景描述:项目之前在真机上和模拟器上运行好好的,开发新功能后突然运行启动后app就闪退,xcode控制台日志为:
[Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated.}
百度了网上的办法,基本都是在终端输入下列命令
xcrun simctl spawn booted log config
--mode "level:off"
--subsystem com.apple.CoreTelephony
我使用上述命令控制台报错:
xiaomai@xiaomaidegushideMacBook-Pro ~ % xcrun simctl spawn booted log config
--mode "level:off"
--subsystem com.apple.CoreTelephony
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=9):
Process spawn via launchd failed.
Bad file descriptor
Underlying error (domain=NSMachErrorDomain, code=9):
The operation couldn’t be completed. (Mach error 9 - (os/kern) memory failure)
zsh: command not found: --mode
zsh: command not found: --subsystem
xiaomai@xiaomaidegushideMacBook-Pro ~ %
找这个问题调试了两三小时,回想自己只开发了新代码没有做其他为啥出现这种问题,因为我开发时候使用模拟器调试,我查询网上资料我以为只有模拟器会这样,后来使用真机调试也遇到一样的问题。
换个思路解决问题:前提是项目使用git管理,使用git status查看本地变动,发现main.m也修改了,what?我没有修改那个代码
去掉return UIApplicationMain(argc, argv, nil, appDelegateClassName);重新运行解决了问题
总结:如果出现类似问题首先执行命令,如果执行命令解决不了,检查是否return UIApplicationMain(argc, argv, nil, appDelegateClassName);被注释掉了(我在开发中都没打开那个文件,怎么注释的也不知道,可能是无意间点错了注释掉了)