简体   繁体   中英

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)
        }       
    }
}

You can require that the device support nfc in your info.plist .

Per Apple: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/DeviceCompatibilityMatrix/DeviceCompatibilityMatrix.html

  • nfc requires an iPhone 7 or higher and is unsupported across all iPads

在此处输入图片说明

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM