I need to check if the application is moved to the background. Why?
Good, because my application works with bluetooth, and only one person can be connected to this device at a time. Therefore, if they do not use it and the application is in the background, disable them and send them to the main connection page.
Now I have achieved this. I have a selector in the main first class and a function to disable and send to the first page. But I did not understand that if the control panel is being dragged, the application is in the "background".
From looking around, there seems to be no way to determine if the control panel is rising. So does anyone have any ideas on how I can do this differently?
Actually, I just want the application to be moved to the background for some other reason, except for the raised control panel, to disconnect from the device.
Selection:
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: Notification.Name.UIApplicationWillResignActive, object: nil)
Functions:
@objc func appMovedToBackground() {
if (ViewController.connectedPeripheral != nil) {
print("App moved to background!")
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "connectView") as! ViewController
self.navigationController?.pushViewController(nextViewController, animated: true)
ViewController.centralManager.cancelPeripheralConnection(ViewController.connectedPeripheral!)
}
else {
print("App moved to background but no device is connected so no further action taken")
}
}
This is not a duplicate of other issues. I know how to check if an application is in the background. I just don't want to turn off when the control panel rises ...
source
share