0

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)
        }       
    }
}
NinjaDeveloper
  • 1,620
  • 3
  • 19
  • 51
  • 2
    "I want to the ok button to exit the application" Don't. Don't quit the app, it will be understand as a crash. Cf. https://stackoverflow.com/questions/14335848/exit-application-when-click-button-ios/ – Larme Dec 17 '18 at 17:40
  • 2
    Since your deployment target is iOS 11 then you don't need any checks for iOS 11 since no one with iOS 10 will be able to install the app. – rmaddy Dec 17 '18 at 17:42
  • 1
    Why don't you want to support iPhone 7 or older? What about iPads (all iPhone-only apps can run on iPads). – rmaddy Dec 17 '18 at 17:43
  • 1
    You could use this https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/DeviceCompatibilityMatrix/DeviceCompatibilityMatrix.html but there is nothing that seems to block iPhone7 or lower. You should manage the cases. Why not iPhone 7? – Larme Dec 17 '18 at 17:44
  • @rmaddy it is one of the requirements the target device is iPhone 8 and OS iOS 11 – NinjaDeveloper Dec 17 '18 at 17:48
  • 2
    But why? There are proper solutions but we need to know why so the correct answer can be given. And again, what about iPads? – rmaddy Dec 17 '18 at 17:53
  • ok I no need to hard code the iOS version check if I use the deployment target but what about the hardware – NinjaDeveloper Dec 17 '18 at 17:53
  • 1
    If we can't understand why you can't allow iPhone 7 or lower, its hard to tell, because as I link the Matrix, there seems to be no "discriminant" to avoid them. So it might be in fact a way to accept iPhone 7 and give you reason why/how (if you need to convince client/manager, etc.) Well, if you don't want to go on the AppStore and only in Private Enterprise Store, it should be okay though. – Larme Dec 17 '18 at 17:54
  • @rmaddy our System Archticter decided that we need to target iOS11 and iphone 8 and above iPad support come later and we target only in Private Enterprise Store – NinjaDeveloper Dec 17 '18 at 17:56
  • 1
    As I said, all iPhone apps run on iPads. – rmaddy Dec 17 '18 at 17:59
  • 1
    If this is for a private enterprise store, I guess you can get away with this, but in the public iTunes Store you can only restrict devices by restricting to libraries in info plist. For example, ARKit. If you're app using ARKIt, only supported on some devices, you can list this in your info plist and then only those devices can install the app. However, you can not restrict devices once the app is live in production. Here's a post about ARKit for example. https://stackoverflow.com/questions/46569624/xcode-how-do-i-set-compatible-devices-to-only-arkit-compatible-devices – Augie Dec 17 '18 at 18:01
  • @rmaddy for now, we are targeting iOS 11 we can do that using deployment target. our target device is iphone 8 and above no iPad support – NinjaDeveloper Dec 17 '18 at 18:18
  • Try this:https://stackoverflow.com/a/46234519/4311935 and you can use private APIs to check device – canister_exister Dec 17 '18 at 18:34

2 Answers2

1

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

enter image description here

enter image description here

CodeBender
  • 35,668
  • 12
  • 125
  • 132
1

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.

Rainer Schwarz
  • 380
  • 3
  • 9