webViewWebContentProcessDidTerminate是否曾为后台运行的应用程序调用过



如果应用程序在前台运行时WKWebView终止,则会在其委托上调用webViewWebContentProcessDidTerminate

但是,如果应用程序在后台,会发生什么?

它还会立即收到回调吗?当应用程序稍后被预测时,它会收到它吗?它根本不运行吗?

我目前不知道如何触发终止——否则我只会尝试一下

我之所以这么问,是因为我想让它重新加载被终止的web视图,以避免我的应用程序出现空白屏幕,但我不确定这是否真的适用于后台运行的应用程序。

如果您正在运行模拟器,您可以从命令行终止web内容进程以触发webViewWebContentProcessDidTerminate调用:

# In the command line, find the PID of your simulator process:
ps -p `pgrep launchd_sim`
# or if you have many simulators running:
ps -A | grep launchd_sim
# Find the PID of the WebContent process:
pgrep -P <simulator-pid> 'com.apple.WebKit.WebContent'
# kill it
kill <webcontent-pid>
# or if you want a one-lner:
kill $(pgrep -P $(pgrep launchd_sim) 'com.apple.WebKit.WebContent')

要点如下:https://gist.github.com/jasonbekolay/dad7c446ae1b02f174dc3eb3a5ea70ee

对我来说,只有当我的应用程序在后台,并且iOS没有内存用于其他应用程序终止我应用程序中的WKWebView时,WKWebView才会终止。如果再次打开应用程序,WKWebView将被破坏,并调用webViewWebContentProcessDidTerminate

尝试按照@joemasilotti的指示进行复制:

  1. 在WKWebView处于活动状态的情况下打开应用程序
  2. 在后台移动您的应用程序-不要终止它
  3. 打开许多其他应用程序来使用内存,或者玩一个图形密集的游戏,看几秒钟
  4. 尝试再次打开你的应用程序,你应该会看到一个空白/灰色的屏幕

相关内容

最新更新