0

I connected my App with Parse server with push notification but the problem is i got error and it says: registerforRemotenotification type was deprecated in IOS version 8.0: please use register for remote notification and register user notification setting instead. but this code is for IOS8.

Can anyone help me with right code?

    if application.applicationState != UIApplicationState.Background {


        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)
    }


    return true
}
![enter image description here][1]
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
Steven
  • 762
  • 1
  • 10
  • 27

1 Answers1

0

Depending on what you want:

  • If you don't want your app to be compatible with iOS 7 or earlier, then set your deployment target in your project settings to iOS 8; and only keep the first part of your condition (remove the 'else' part) as the application will always respond to that selector. With a deployment target of iOS 8, compiler is telling you that if you get to that line you would be executing a deprecated statement on an iOS 8 device.
  • If you want your app to be compatible with iOS 7 or earlier, then make sure your deployment target in your project settings is set to iOS 7 or earlier; the warnings should then go away, if not you can try to silent it with something like described here deprecated warnings in xcode and how to handle deprecation
Community
  • 1
  • 1
JP Hribovsek
  • 6,707
  • 2
  • 21
  • 26