Search code examples
iosswiftios7ios8

ios7 registerForRemoteNotificationTypes doesn't get prompted to ask the user for permission


When i setup notifications in the AppDelegate only ask to user for permission under iOS8 despite i reset the simulator settings (i know remote notifications doesnt work in simulator, but i dont have a device with ios7 to test it, but i'm surprised that its not asking to allow remote notifications).

        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)

        }

And this is how i check ios7 or 8 which works:

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

I also read this http://corinnekrych.blogspot.com.es/2014/07/how-to-support-push-notification-for.html


Solution

  • Push Notifications were NOT supported on iOS simulator. It seems it's only since iOS 8 that this alert is displayed (which doesn't mean notifications work with the simulator). See this SO question

    So you have to find a device running iOS 7, but your code seems good.