The answer is pretty black and white. Yes, you can just swap it, with one caveat:
If you target devices with iOS 7, you wonβt need it. However, if you are developing for iOS7 ... my opinion is to stop it. As of August 31 and According to Apple , there are not many users who still have this OS on their device, and that the data does not even include public iOS 9, so you spend a lot of time on OSs that no one uses. However, if you really need to support iOS 7, you need to include all this in addition to outdated versions. Otherwise, you can simply change it, as you stated with non-obsolete versions.
Here is an example of Swift 2.0:
if #available(iOS 8.0, *) { let types: UIUserNotificationType = [.Alert, .Badge, .Sound] let settings = UIUserNotificationSettings(forTypes: types, categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } else { let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] application.registerForRemoteNotificationTypes(types) }
source share