Skip to main content
 首页 » 操作系统

ios之迪尔德 : Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings when trying to run on iOS7

2024年01月01日45zengkefu

<分区>

我正在使用 Swift。我正在尝试向用户请求权限。

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

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

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

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

dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings Referenced from: /var/mobile/Applications/07D5D4BE-E6A3-43EE-ABEB-E9A1E4658F75/MyFirstApp.app/MyFirstApp Expected in: /System/Library/Frameworks/UIKit.framework/UIKit in /var/mobile/Applications/07D5D4BE-E6A3-43EE-ABEB-E9A1E4658F75/MyFirstApp.app/MyFirstApp (lldb)

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

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; 

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

有什么想法吗?请帮忙。