【问题标题】:iOS/Swift test for UIAlertController/UIAlertViewiOS/Swift 测试 UIAlertController/UIAlertView
【发布时间】:2014-11-20 10:57:19
【问题描述】:

我正在开发一个需要在 iOS 7 和 8 上运行的应用程序。如果可能,我想使用 UIAlertController,如果不回退到 UIAlertView。

我用这个测试:

    let gotUIAlertController:AnyClass? = NSClassFromString("UIAlertController")
    if( gotUIAlertController != nil )
    {
        // Do UIAlertController
    }
    else
    {
        // DO UIAlertView
    }

这似乎适用于 iOS8 模拟器,处于调试模式,但在发布模式(或使用仪器运行调试模式)时,gotUIAlertController 不为零,因此 UIAlertController 正在尝试呈现并且应用程序崩溃。部署目标是 7.1,bas SDK 设置为 8.1

谁能告诉我为什么这段代码在 iOS7.1 上以这种方式执行?

【问题讨论】:

    标签: ios swift uialertview ios7.1 uialertcontroller


    【解决方案1】:

    我不知道为什么,但我找到的解决方法是:

    let gotUIAlertController: AnyObject? = objc_getClass("UIAlertController".UTF8String)
    if( gotUIAlertController != nil ) {
        // Do UIAlertController
    }
    else {
        // DO UIAlertView
    }
    

    【讨论】:

    • 谢谢。时间限制导致我获取系统设备信息并检查 >= 8.0 这并不漂亮,但可以完成工作(目前)。我将在进一步的版本中使用你的方法。谢谢你的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 2017-12-07
    • 2022-12-02
    相关资源
    最近更新 更多