1

I am not getting device token in iPhone 5 (10.2.1) and SE(10.3.1) and other 5 related devices but successfully getting tokens in all iPhone 6 (including plus, SE) and 7, and 7+ also.

This is my code for registering

func registerForPushNotification(let application: UIApplication) {
    let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerUserNotificationSettings(pushNotificationSettings)

    application.applicationIconBadgeNumber = 0

    if pushNotificationSettings.types != .None {
        application.registerForRemoteNotifications()
    }
}

And this is my code for collecting token

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    let characterSet: NSCharacterSet = NSCharacterSet( charactersInString: "<>" )
    let deviceTokenString: String = ( deviceToken.description as NSString )
        .stringByTrimmingCharactersInSet( characterSet )
        .stringByReplacingOccurrencesOfString( " ", withString: "" ) as String
    print( deviceTokenString )
}

Any help?

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80

1 Answers1

0

I have handled didRegisterUserNotificationSettings in my AppDelegate

Like this

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    if notificationSettings.types != [] {
        application.registerForRemoteNotifications()
    }   
}

This solved the issue which was suggested by @Lion

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80