Search code examples
iosiphoneswiftios11

prompt the user using a UIAlertController if iOS and device lower than iOS11 and iphone 8?


If a user installs up an application in a device lower than iPhone 8 and iOS version lower than iOS 11, a UI Alert pop" the minimum requirements to use the app is iOS 11 and iPhone 8 or above", and there is an ok button. I want to tell the user that is their device is not supported. Here is what I have in the code.

Note: I did set the deployment target to iOS11 but how can I set it for device iPhone8

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()       
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let alertController = UIAlertController(title: "Foo", message: "Bar", preferredStyle: .alert)

        alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
        // check
        if #available(iOS 11.0,*)
        {

        }
        else
        {
            present(alertController, animated: true, completion: nil)
        }       
    }
}

Solution

  • If you really, Really, REALLY (be sure) want to restrict usage of your app to iPhone 8 during runtime, you can read out the device model with this little extension to UIDevice from this SO Answer.

    Beware, that Apple may not - or most likely will not - let you publish your app to the AppStore. Highly avoid killing the app by code!! Just show the alert, that your app is not designed to run on any device other than iPhone 8.