0

I am tring to implement push notification in iOS. I have successfully made it working once. But now I am facing a strange issue. I have exited XCode and reopened it, no code was changed, I am still getting the deviceToken, but now I am not receiving any push notification on my device. I am also using Firebase to get the notification, it was also working fine, but now it is giving me blank string as device token.

In AppDelegate I am using the following code:

    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

//This is triggered and I am getting the push notification token but using this instead of firebase token to send directly via APNS is also not working.
public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
}

//This is triggered but the token here is a blank string
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    Messaging.messaging().subscribe(toTopic: "ios_topic")
}

This was working till I quit XCode, but suddenly it stopped working without any code changes. I tried everything including a system restart. Sometimes the didRegisterForRemoteNotificationsWithDeviceToken is getting called twice during fresh installs, once before I give permissions and once after the permissions are granted.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Harikrishnan
  • 7,765
  • 13
  • 62
  • 113

1 Answers1

0

Maybe ist because device tokens are now being parsed as '32BYTES'.

See more here:

Swift 3 - device tokens are now being parsed as '32BYTES'

Steffen L.
  • 31
  • 1
  • 8