iOS WKWebView后台崩潰問題排查


最近測試提出了一個bug,App在后台運行一段時間之后,在切換到前台時就自動跳轉到了登錄頁,不是之前的頁面了,經過兩天的排查解決了問題,記錄一下

  1. 我們的項目主要是網頁,App只提供一個webview用來展示網頁內容,所有的操作基本上都是在網頁內完成的,可是測試說App在后台一段時間之后就會自動跳回網頁的登錄頁,感覺應該是網頁的問題。
  2. 首先想到是不是網頁內的邏輯問題,找了前端網頁的代碼看看,發現普通請求報錯403或者401的時候回直接跳轉到登錄頁,感覺應該是這里導致的。問了測試是不是調用了什么接口報錯導致跳回了登錄頁,回答是看后端日志沒有接口報錯,那這就比較奇怪了。因為這里可能性最大,所以我就一直測試,看是否能復現這個問題,試了試好像也沒啥問題,不論抓包還是看log都沒啥異常。
  3. 再三和測試確認了,發現只有最新款的iPhone13有這個問題,其他手機沒問題。我想應該是iOS新系統導致的問題,沒辦法只能升級手機到最新系統iOS 15,在把手機連着電腦,同時開着Charles進行測試,果然登錄幾個小時之后,在XCode里看到了下面一段日志:
    2021-12-07 17:33:37.675132+0800 xxx_app[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 xxx_app[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 xxx_app[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 xxx_app[1088:197408] [Process] 0x116360190 - NetworkProcessProxy::didClose (Network Process 0 crash)
    2021-12-07 17:33:37.684669+0800 xxx_app[1088:197408] [Process] 0x1163d0600 - [PID=1095] WebProcessProxy::didClose: (web process 0 crash)
    2021-12-07 17:33:37.684717+0800 xxx_app[1088:197408] [Process] 0x1163d0600 - [PID=1095] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=4
    2021-12-07 17:33:37.684823+0800 xxx_app[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 xxx_app[1088:197408] [Process] 0x1030b1e18 - [pageProxyID=5, webPageID=6, PID=1095] WebPageProxy::processDidTerminate: (pid 1095), reason 4
    2021-12-07 17:33:37.678491+0800 xxx_app[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 xxx_app[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 xxx_app[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 xxx_app[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 xxx_app[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}
    
  4. 經過搜索和分析日志,發現應該是App在后台的時候,WebProcess被kill;當App切換前台時,會重新啟動一個WebProcess,但是之前存在webview的session里的信息都沒有了,導致網頁直接跳轉回來登錄頁。
  5. 找到問題就想有什么好的解決方法,比較簡單就是在后台檢測到webview被kill時,直接退出App,等下次切換到前台的時候相當於重新打開App;更好的方法是檢測到webview被kill時,直接重新啟動一個新的webview,把所有保存的信息復制過去;但是因為時間比較緊急就按照簡單的方法解決了問題。
    - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
        NSLog(@"webViewWebContentProcessDidTerminate");
        exit(0);
    }
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM