Detect when home button is pressed iOS
Posted
by
nick
on Stack Overflow
See other posts from Stack Overflow
or by nick
Published on 2012-04-25T22:15:36Z
Indexed on
2012/11/06
23:01 UTC
Read the original article
Hit count: 169
I have several iOS apps that all use the same port to listen for a network beacon. On the main view I use viewWillDisappear to close the port when another view is opened, which was working great. Then I noticed if I pressed the home button from the main view controller without opening another view to close the port, then the port stays open and non of my other apps can listen on that port any more. I then tried using viewWillUnload, but that doesn't seem to get called when I press the home button.
-(void)viewWillUnload
{
//[super viewWillUnload];
NSLog(@"View will unload");
[udpSocket close];
udpSocket = nil;
}
View will unload is never displayed in the console, which leads me to believe that the method is never getting called.
Is there a way to detect when the home button is pressed so I can close my port?
© Stack Overflow or respective owner