How can I tell my app is about to become inactive/go to background state?
I am assuming I need to implement:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(resignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
but am not sure if this is the right notification to determine my app is abo开发者_StackOverflow社区ut to leave active state.
Is this a good place to cancel network connections, along with app termination?
There are cases where UIApplicationWillResignActiveNotification
is sent but the application does not enter the background, for example if a call is received but the user chooses not to answer it.
Use UIApplicationDidEnterBackgroundNotification
to be notified when entering the background. Be aware that this will sometimes be sent after UIApplicationWillEnterForegroundNotification
if the application is quickly opened again.
精彩评论