0

I have a swift app that I am bridging from the Objective C Parse framework.

It does not crash in the simulator, but push notifications don't work in the simulator.

Here is the code:

Parse.setApplicationId("id", clientKey: "id")
    let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
    let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
    UIApplication.sharedApplication().registerForRemoteNotifications()
    return true

It crashes on the following line without a error message:

UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)

How can I fix this?

UPDATE

I just tested it on my iPad (iOS 8) and now it is crashing there too?

Haring10
  • 1,517
  • 1
  • 19
  • 37

1 Answers1

0

If it crash in iOS<8 its because -registerUserNotificationsSettings() work only on iOS8.

Try something like that :

let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)


if(UIApplication.sharedApplication().respondsToSelector(@selector(registerUserNotificationSettings:))){
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
    UIApplication.sharedApplication().registerForRemoteNotifications()
}else{
    UIApplication.sharedApplication().registerForRemoteNotificationsTypes(notificationTypes)
}
Vincent
  • 188
  • 5
  • It says unresolved identifier `registerUserNotificationSettings` – Haring10 Oct 28 '14 at 05:36
  • When I take out `@selector(registerUserNotificationSettings:)` and put in just `registerUserNotificationSettings`, then it says `'UIApplication does not have member named 'registerUserNotificationSettings'` – Haring10 Oct 28 '14 at 05:40