不会提示ios7 registerForRemoteNotificationTypes询问用户是否允许

时间:2015-03-13 16:15:05

标签: ios swift ios7 ios8

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

        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

1 个答案:

答案 0 :(得分:0)

iOS模拟器不支持推送通知。似乎仅在iOS 8之后显示此警报(这并不意味着通知与模拟器一起工作)。 See this SO question

所以你必须找到一个运行iOS 7的设备,但你的代码似乎很好。