【问题标题】:dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings when trying to run on iOS7 [duplicate]dyld:找不到符号:尝试在iOS7上运行时_OBJC_CLASS_$_UIUserNotificationSettings [重复]
【发布时间】:2014-08-23 11:53:15
【问题描述】:

我正在使用 Swift。我正在尝试向用户询问权限。

我正在使用此代码来询问用户权限:

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))

此代码在 iOS8 模拟器上运行良好

但是当我尝试在 iOS7 的 iPad 2 上构建和运行我的应用程序时,我的应用程序崩溃并显示消息

dyld:未找到符号:_OBJC_CLASS_$_UIUserNotificationSettings 引用自:/var/mobile/Applications/07D5D4BE-E6A3-43EE-ABEB-E9A1E4658F75/MyFirstApp.app/MyFirstApp 预期在:/System/Library/Frameworks/UIKit.framework/UIKit 在 /var/mobile/Applications/07D5D4BE-E6A3-43EE-ABEB-E9A1E4658F75/MyFirstApp.app/MyFirstApp (lldb)

在 Obj-C 中请求用户权限,我们使用

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];

但在 swift 中 application 对象没有名为 registerForRemoteNotificationTypes 的方法

有什么想法吗?请帮忙。

【问题讨论】:

    标签: ios ios7 swift


    【解决方案1】:

    UIUserNotificationSettings 仅适用于 iOS 8。所以你必须这样做:

    if NSClassFromString("UIUserNotificationSettings") != nil {
        // Do the things in iOS 8 way.
    } else {
        // Do the things in iOS 7 way.
    }
    

    上面的代码在 iOS 7 上曾经崩溃,但这个问题应该在 Beta6 中修复。

    【讨论】:

    • 是的,我知道UIUserNotificationSettings 仅在 iOS8 中可用。 iOS7的方式怎么做?
    • 'registerForRemoteNotificationTypes' 在 Swift 中为我工作。 UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Badge | .Alert | .Sound)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多