【问题标题】:prompt the user using a UIAlertController if iOS and device lower than iOS11 and iphone 8?如果 iOS 和设备低于 iOS11 和 iphone 8,则提示用户使用 UIAlertController?
【发布时间】:2018-12-17 17:36:55
【问题描述】:

如果用户在低于 iPhone 8 且 iOS 版本低于 iOS 11 的设备上安装应用程序,则会弹出 UI Alert“使用该应用程序的最低要求是 iOS 11 和 iPhone 8 或更高版本”,并且有确定按钮。我想告诉用户他们的设备不受支持。这是我在代码中的内容。

注意:我确实将部署目标设置为 iOS11,但如何为设备 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)
        }       
    }
}

【问题讨论】:

  • “我想按确定按钮退出应用程序”不要。不要退出应用程序,它会被理解为崩溃。参照。 stackoverflow.com/questions/14335848/…
  • 由于您的部署目标是 iOS 11,因此您不需要对 iOS 11 进行任何检查,因为使用 iOS 10 的人将无法安装该应用程序。
  • 为什么不想支持 iPhone 7 或更早版本? iPad 怎么样(所有仅限 iPhone 的应用程序都可以在 iPad 上运行)。
  • 您可以使用这个developer.apple.com/library/archive/documentation/…,但似乎没有什么可以阻止 iPhone7 或更低版本。您应该管理这些案例。为什么不是 iPhone 7?
  • 但是为什么呢?有适当的解决方案,但我们需要知道为什么才能给出正确的答案。再说一次,iPad 呢?

标签: ios iphone swift ios11


【解决方案1】:

如果你真的,真的,真的(确定)想在运行时限制你的应用程序在 iPhone 8 上的使用,你可以从这个SO Answer 读出带有这个小扩展的设备型号到UIDevice

请注意,Apple 可能不会 - 或者很可能不会 - 让您将应用发布到 AppStore。高度避免通过代码杀死应用程序!只需显示警报,即您的应用并非设计为在 iPhone 8 以外的任何设备上运行。

【讨论】:

    【解决方案2】:

    您可以要求设备在您的info.plist 中支持nfc

    每个苹果: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/DeviceCompatibilityMatrix/DeviceCompatibilityMatrix.html

    • nfc 需要 iPhone 7 或更高版本,并且不受所有 iPad 支持

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 2023-04-09
      • 1970-01-01
      • 2015-09-01
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      相关资源
      最近更新 更多