ios7 注册远程通知类型不会提示请求用户权限



当我在AppDelegate中设置通知时,尽管我重置了模拟器设置,但仅在iOS8下请求用户的权限(我知道远程通知在模拟器中不起作用,但我没有装有ios7的设备来测试它,但我很惊讶它没有要求允许远程通知)。

        if iOS8 {
            println("ios 8")
            let userNotificationTypes: UIUserNotificationType = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound)
            let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
            application.registerUserNotificationSettings(settings)
            application.registerForRemoteNotifications()
        } else {
            println("ios 7")
            let userNotificationTypes: UIRemoteNotificationType = (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)
        application.registerForRemoteNotificationTypes(userNotificationTypes)
        }

这就是我检查ios7或8工作的方式:

private let iosVersion = NSString(string: Device.systemVersion).doubleValue
let iOS8 = iosVersion >= 8
let iOS7 = iosVersion >= 7 && iosVersion < 8

我也读过这个 http://corinnekrych.blogspot.com.es/2014/07/how-to-support-push-notification-for.html

iOS 模拟器不支持推送通知。似乎只有从iOS 8开始才会显示此警报(这并不意味着通知适用于模拟器)。看到这个SO问题

所以你必须找到一个运行iOS 7的设备,但你的代码看起来不错。

最新更新