Following the Parse.com tutorial for push notifications, I put this Swift code into my application didFinishLaunchingWithOptions method:
// 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'm getting these two warnings:
'UIRemoteNotificationType' was deprecated in iOS version 8.0: Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead.
'registerForRemoteNotificationsTypes' was deprecated in iOS version 8.0: Please use registerForRemoteNotifications and registerUserNotificationSettings: instead
Can I simply just swap out what it's telling me to?
The answer is pretty black and white. Yes you can simply swap it out, with one caveat:
If you are targeting devices with iOS 7, then no you need that. However, if you are developing for iOS7...my opinion, stop it. As of Aug 31 and According to Apple there isn't that many users who still have this OS on their device, and that data isn't even including the public iOS 9s, so your wasting a lot of your time on an OS no one uses. However if you really have to support iOS 7 you need to include all of that in addition to the non-deprecated versions. Otherwise, you can just swap it out as you stated with the non-deprecated versions.
Here's a Swift 2.0 example :
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With