i got an test app I\'m writing with Swift, I want to target iOS 7. But enable local notification I need to add
application.registerUserNotificationSettings(
There is a very good answer by Prasath, but it is written in Objective-C,
so I have written something similar in swift:
(tested in Xcode 6 )
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// ...
// Set Notification
if UIApplication.sharedApplication().respondsToSelector(Selector("registerUserNotificationSettings:")) {
// Notifications for iOS 8
let notificationSettings = UIUserNotificationSettings(forTypes: .Alert | .Sound, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
}
else {
// Notifications for iOS < 8
UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Alert | .Sound)
}
// ...
return true
}
Hope that helps