如何正确删除SFSafariViewController作为子视图控制器? [英] How to remove SFSafariViewController as a child view controller correctly?
问题描述
我正在使用此SO答案提供的技术,将某些URL预先加载到SFSafariViewController中,如下所示:
I am using the technique provided by this SO answer to preload some URL in SFSafariViewController like this:
addChildViewController(svc)
svc.didMoveToParentViewController(self)
view.addSubview(svc.view)
然后我尝试使用以下代码删除Safari View控制器:
And I try to remove the Safari View controller with following code:
svc.willMoveToParentViewController(nil)
svc.view.removeFromSuperview()
svc.removeFromParentViewController()
现在,我可以预加载URL并显示Safari View,而不会出现问题.但是,当我重复几次该过程(预加载/显示/删除)(大约30次以上)后,由于某些内存问题,该应用将崩溃,因为当应用崩溃时日志显示Memory level is not normal or this app was killed by jetsam
.
Now I can preload the URL and show the Safari View without problem. However, after I repeat the process (preload/show/remove) several times (probably 30+ times) , the app will crash due to some memory issue because the log shows Memory level is not normal or this app was killed by jetsam
when the app crashes.
在崩溃之前,我看到了一些有关可能的泄漏警告的日志:
Before crash, I saw some logs about possible-leak warnings:
<Warning>: notify name "UIKeyboardSpringBoardKeyboardShow" has been registered 20 times - this may be a leak
<Warning>: notify name "com.apple.SafariViewService-com.apple.uikit.viewService.connectionRequest" has been registered 20 times - this may be a leak
在删除Safari View控制器时我可以正确执行吗?我想念什么吗?或有任何解决此问题的建议?
Am I doing it correctly when removing the Safari View controller? Am I missing something? Or any suggestion to work around this issue?
推荐答案
您可能正在泄漏svc
.删除后将其清除.
you are probably leaking svc
. nil it out after removing it.
svc.willMoveToParentViewController(nil)
svc.view.removeFromSuperview()
svc.removeFromParentViewController()
svc = nil
如果这不能解决问题,请尝试启用僵尸或使用泄漏工具
if this doesn't solve it, try enabling zombies or use the leaks instrument
这篇关于如何正确删除SFSafariViewController作为子视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!