iOS WKWebView后台崩溃问题排查

最近测试提出了一个bug,App在后台运行一段时间之后,在切换到前台时就自动跳转到了登录页,不是之前的页面了,经过两天的排查解决了问题,记录一下

  1. 我们的项目主要是网页,App只提供一个webview用来展示网页内容,所有的操作基本上都是在网页内完成的,可是测试说App在后台一段时间之后就会自动跳回网页的登录页,感觉应该是网页的问题。
  2. 首先想到是不是网页内的逻辑问题,找了前端网页的代码看看,发现普通请求报错403或者401的时候回直接跳转到登录页,感觉应该是这里导致的。问了测试是不是调用了什么接口报错导致跳回了登录页,回答是看后端日志没有接口报错,那这就比较奇怪了。因为这里可能性最大,所以我就一直测试,看是否能复现这个问题,试了试好像也没啥问题,不论抓包还是看log都没啥异常。
  3. 再三和测试确认了,发现只有最新款的iPhone13有这个问题,其他手机没问题。我想应该是iOS新系统导致的问题,没办法只能升级手机到最新系统iOS 15,在把手机连着电脑,同时开着Charles进行测试,果然登录几个小时之后,在XCode里看到了下面一段日志:
  4. 再三和测试确认了,发现只有最新款的iPhone13有这个问题,其他手机没问题。我想应该是iOS新系统导致的问题,没办法只能升级手机到最新系统iOS 15,在把手机连着电脑,同时开着Charles进行测试,果然登录几个小时之后,在XCode里看到了下面一段日志:
    2021-12-07 17:33:37.675132+0800 国网高培云课堂[1088:221122] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
    2021-12-07 17:33:37.676720+0800 国网高培云课堂[1088:221122] [ProcessSuspension] 0x1163faac0 - ProcessAssertion: Failed to acquire RBS assertion 'WebProcess Background Assertion' for process with PID=1095, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
    2021-12-07 17:33:37.678389+0800 国网高培云课堂[1088:221122] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
    2021-12-07 17:33:37.681365+0800 国网高培云课堂[1088:197408] [Process] 0x116360190 - NetworkProcessProxy::didClose (Network Process 0 crash)
    2021-12-07 17:33:37.684669+0800 国网高培云课堂[1088:197408] [Process] 0x1163d0600 - [PID=1095] WebProcessProxy::didClose: (web process 0 crash)
    2021-12-07 17:33:37.684717+0800 国网高培云课堂[1088:197408] [Process] 0x1163d0600 - [PID=1095] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=4
    2021-12-07 17:33:37.684823+0800 国网高培云课堂[1088:197408] [ProcessSuspension] 0x1163faca0 - ProcessAssertion: Failed to acquire RBS Background assertion 'ConnectionTerminationWatchdog' for process because PID is invalid
    2021-12-07 17:33:37.686948+0800 国网高培云课堂[1088:197408] [Process] 0x1030b1e18 - [pageProxyID=5, webPageID=6, PID=1095] WebPageProxy::processDidTerminate: (pid 1095), reason 4
    2021-12-07 17:33:37.678491+0800 国网高培云课堂[1088:221122] [ProcessSuspension] 0x1163fab20 - ProcessAssertion: Failed to acquire RBS assertion 'NetworkProcess Background Assertion' for process with PID=1096, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
    2021-12-07 17:33:37.690991+0800 国网高培云课堂[1088:221122] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
    2021-12-07 17:33:37.691127+0800 国网高培云课堂[1088:221122] [ProcessSuspension] 0x1163fab80 - ProcessAssertion: Failed to acquire RBS assertion 'WebProcess Foreground Assertion' for process with PID=1095, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
    2021-12-07 17:33:37.692469+0800 国网高培云课堂[1088:221122] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
    2021-12-07 17:33:37.692563+0800 国网高培云课堂[1088:221122] [ProcessSuspension] 0x1163fabe0 - ProcessAssertion: Failed to acquire RBS assertion 'NetworkProcess Foreground Assertion' for process with PID=1096, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
    
  5. 经过搜索和分析日志,发现应该是App在后台的时候,WebProcess被kill;当App切换前台时,会重新启动一个WebProcess,但是之前存在webview的session里的信息都没有了,导致网页直接跳转回来登录页。
  6. 找到问题就想有什么好的解决方法,比较简单就是在后台检测到webview被kill时,直接退出App,等下次切换到前台的时候相当于重新打开App;更好的方法是检测到webview被kill时,直接重新启动一个新的webview,把所有保存的信息复制过去;但是因为时间比较紧急就按照简单的方法解决了问题。
    - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
        NSLog(@"webViewWebContentProcessDidTerminate");
        exit(0);
    }
    
上一篇:07-Dart 类的继承


下一篇:[数据库 07] lombok 一对多多对一 动态 缓存