我在用斯威夫特。我试图向用户询问权限。
我使用此代码询问用户权限:
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))此代码在iOS8模拟器上运行良好。
但是当我试图在iPad 2上用iOS7构建和运行我的应用程序时,我的应用程序正在崩溃。
dyld:符号未找到:从: /var/mobile/Applications/07D5D4BE-E6A3-43EE-ABEB-E9A1E4658F75/MyFirstApp.app/MyFirstApp引用的_OBJC_CLASS_$_UIUserNotificationSettings预期在: /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];但是在application对象中没有名为registerForRemoteNotificationTypes的方法。
有什么想法吗?请帮帮忙。
发布于 2014-08-23 13:05:42
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解决。
https://stackoverflow.com/questions/25461654
复制相似问题