I've a ViewController which is named mapViewController. Inside that controller I've a button which is a play button. If the button is clicked a boolean named "Play" will change from false to true.
Let's jump to the point of this thread:
Once I press the button, I want the boolean to be changed to true. If the user leaves the application. (Entering the background) I want to print out a text which displays that. (I'll use this for other purposes as soon as I get an idea how this works.)
So, let's take a look at my AppDelegate
func applicationDidEnterBackground(_ application: UIApplication)
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
let mapVC = UIApplication.shared.delegate as! MapViewController
if (mapVC.play == true)
{
print("The play-bool is true, and application did enter the background")
}
}
Once I press the button, and leaves the application I'm getting an error which looks like this:
Could not cast value of type 'MyDogwalk.AppDelegate' (0x28093e230) to 'MyDogwalk.MapViewController' (0x104f99d98).
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
As you can see on my code, I'm trying to get a boolean from a ViewController, and check it's statement inside my AppDelegate.
I'll use this information to track locations once the phone is in the background, but as this is my first time. I need/want to understand how this actually works, and how I can do this.