Is dealloc always called? Even when you swipe close an app?

怎甘沉沦 提交于 2019-12-12 01:48:03

问题


I wonder if dealloc is always called when you close a ViewController in Objective-C for iOS. I've done some tests and it seems like it. Except I don't get any logs when I swipe close the application. I figured that maybe XCode doesn't log things if you fully close the app like that.

The reason I wonder this is because I'm sending analytic data when one of the ViewControllers closes and I kinda need to know if dealloc is always called or if there's any better way doing this.


回答1:


It's not defined when dealloc will be called for a view controller (or pretty much any class), therefore don't use it for sending analytics.

Use viewDidDisappear instead, which you can rely on to be called when the view controller has been removed.




回答2:


If you want to get notified when app is killed via Swiping , you can use applicationWillTerminate method and in this method , you can check for current view controller in navigation stack and send analytical data for that View controller .



来源:https://stackoverflow.com/questions/27523768/is-dealloc-always-called-even-when-you-swipe-close-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!