ios - How to remove SFSafariViewController as a child view controller correctly? -


i using technique provided this answer preload url in sfsafariviewcontroller this:

addchildviewcontroller(svc) svc.didmovetoparentviewcontroller(self) view.addsubview(svc.view) 

and try remove safari view controller following code:

svc.willmovetoparentviewcontroller(nil) svc.view.removefromsuperview() svc.removefromparentviewcontroller() 

now can preload url , show safari view without problem. however, after repeat process (preload/show/remove) several times (probably 30+ times) , app crash due memory issue because log shows memory level not normal or app killed jetsam when app crashes.

before crash, saw logs possible-leak warnings:

<warning>: notify name "uikeyboardspringboardkeyboardshow" has been registered 20 times - may leak  <warning>: notify name "com.apple.safariviewservice-com.apple.uikit.viewservice.connectionrequest" has been registered 20 times - may leak 

am doing correctly when removing safari view controller? missing something? or suggestion work around issue?

if adding child view controller code have specified above think order should bit different per documentation.

addchildviewcontroller(svc) view.addsubview(svc.view) svc.didmovetoparentviewcontroller(self) 

you should first add child view , call didmovetoparentviewcontroller. try , see if works.

listing 5-1adding child view controller container

  • (void) displaycontentcontroller: (uiviewcontroller*) content { [self addchildviewcontroller:content]; content.view.frame = [self frameforcontentcontroller]; [self.view addsubview:self.currentclientview]; [content didmovetoparentviewcontroller:self]; }

in preceding example, notice call didmovetoparentviewcontroller: method of child. because addchildviewcontroller: method calls child’s willmovetoparentviewcontroller: method you. the reason must call didmovetoparentviewcontroller: method method cannot called until after embed child’s view container’s view hierarchy.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -