3

I'm trying to implement rich push notification but having issue with register push notification.

Anybody help me?

Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98
Ashvin
  • 8,227
  • 3
  • 36
  • 53

1 Answers1

4

I checked the apple doc and found the one way, some Class is depericated in iOS 10 which we using till iOS 9.x

Steps are there:

  1. Add framework UserNotifications
  2. Add one keys in info plist (I did because i'm using background fetch), check screenshot
  3. Use below code and send the token to your server

To register remote notification

let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in

        // Enable or disable features based on authorization.
        if granted == true
        {
            print("Allow")
            UIApplication.shared.registerForRemoteNotifications()
        }
        else
        {
            print("Don't Allow")
        }
    }

Get Token

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print(deviceToken)
}

enter image description here

Jojodmo
  • 23,357
  • 13
  • 65
  • 107
Ashvin
  • 8,227
  • 3
  • 36
  • 53