问题
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