I made a simple code to clarify my problem. When I run my app on my iPhone it works properly, but when I press home button - either on simulator or my real iPhone - and press the app icon again, the app runs, but the app's button "TestButtonAction don't work. Same problem when I press power/sleep button and turn it on again. same problem either when I duple click home button and terminate my app by sliding it's window away, and rerun it again the button don't work or print "Right Image" in the Console Here is my code, Thanks.
//
// ViewController.swift
// TestingHomeButton
//
// Created by Samuel Oncy on 4/25/18.
// Copyright © 2018 Samuel Oncy. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var TestButtonOutlet: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func TestButtonAction(_ sender: UIButton) {
if(TestButtonOutlet.imageView?.image == UIImage(named:"NatureView")){
print("Right Image")
}
}
}