Parse.com UIRemoteNotificationType Deprecated

Following Parse.com's guide for push notifications, I put this Swift code in my didFinishLaunchingWithOptions app:

// Register for Push Notitications if application.applicationState != UIApplicationState.Background { // Track an app open here if we launch with a push, unless // "content_available" was used to trigger a background push (introduced in iOS 7). // In that case, we skip tracking here to avoid double counting the app-open. let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus") let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:") var pushPayload = false if let options = launchOptions { pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil } if (preBackgroundPush || oldPushHandlerOnly || pushPayload) { PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions) } } if application.respondsToSelector("registerUserNotificationSettings:") { let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } else { let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound application.registerForRemoteNotificationTypes(types) } 

I get these two warnings:

'UIRemoteNotificationType' is deprecated in iOS version 8.0: use UIUserNotificationType to notify users and registerForRemoteNotifications to receive remote notifications.

'registerForRemoteNotificationsTypes' deprecated in iOS version 8.0: use registerForRemoteNotifications and registerUserNotificationSettings: instead

Can I just change what he says to me?

+6
source share
1 answer

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) } 
+5
source

All Articles